如何检查玩家手中是否拿着工具

问题描述 投票:0回答:1

我希望这个 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,但它不起作用,我不明白其他人之前是如何做到的

roblox
1个回答
0
投票

检查父级是角色还是玩家。如果是角色,则它会被持有,但如果是玩家,则它会在库存中。

© www.soinside.com 2019 - 2024. All rights reserved.