我希望这个 roblox 脚本在我手里拿着钥匙并且钥匙在我的背包里时打印钥匙并执行其他操作。
local Players = game:GetService("Players")
local lock = script.Parent
local function onTouched(hit)
local player = Players:GetPlayerFromCharacter(hit.Parent)
if player then
print(player)
local backpack = player:FindFirstChild("Backpack")
if backpack then
print(backpack)
local Key = backpack:FindFirstChild("SilverKey")
if Key then
print(Key)
script.Parent.CanCollide = false
script.Parent.Anchored = false
end
end
end
end
-- Assuming you have a part named "Lock" in the game
local lock = script.Parent -- Change this to the actual lock object
lock.Touched:Connect(onTouched)
我尝试使用chatgpt,但它不起作用,我不明白其他人之前是如何做到的
检查父级是角色还是玩家。如果是角色,则它会被持有,但如果是玩家,则它会在库存中。