Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to get a script know what a player is holding?

Asked by 2 years ago

so, I have this script:

local TweenService = game:GetService("TweenService")

local door = workspace.Door
local doorRoot = door.PrimaryPart

local DoorSwingInfo = TweenInfo.new()

local DoorSwingTween = TweenService:Create(doorRoot, DoorSwingInfo, {
    CFrame = doorRoot.CFrame * CFrame.Angles(0, math.rad(95),0)
})

game.Workspace.Door.ProximityPrompt.Triggered:Connect(function(Player)
    if Player:WaitForChild("Backpack"):FindFirstChild("Key") then
        game.Workspace.Door.ProximityPrompt.Enabled = false

        DoorSwingTween:Play()
    end
end)    

and my problem is when I hold the key and I open the door with the proximityprompt it doesn't work, it only works when i do not hold it. and I probably know it's because the "WaitForChild("Backpack"), that's why its not working... but what should I put instead of "Backpack", since "Hand" doesn't work.

Thanks!

1 answer

Log in to vote
0
Answered by
Puppynniko 1059 Moderation Voter
2 years ago
if Player:WaitForChild("Backpack"):FindFirstChild("Key") or Player.Character:FindFirstChild("Key") then

end
Ad

Answer this question