I know this is probably really easy but I’m new to scripting. I have a door that can be opened using a key that players can get from the workspace. I just don’t know how to make the key get removed from everyone’s backpack when the door opens. Can anyone help? Thanks!
This might not be needed, but here’s the code for my door script.
local debounce = false
local opened = false
script.Parent.Touched:Connect(function(obj)
if obj.Parent.Name == 'Key' and not debounce then
if opened == false then
debounce = true
for i = 1,200 do
game:GetService("RunService").Heartbeat:Wait()
script.Parent.Parent:SetPrimaryPartCFrame(script.Parent.Parent.PrimaryPart.CFrame * CFrame.Angles(0, -0.01, 0))
end
opened = true
debounce = false
end
end
end)
the _ would normally be an i which stands for index but we don’t need that so i changed it to _ (the index would be the backpack) and the v stands for value and the value would be the tool
So I don’t think I was supposed to do this, but I changed the “v” to “tool” and now it’s saying Backpack is not a valid member of Tool "Workspace.Tools.Key
local KeyName = "Key" -- YourToolName Here
for _,Player in pairs(game.Players:GetPlayers()) do
for _,Tool in pairs(Player.Backpack:GetChildren()) do
if Tool:IsA("Tool") and Tool.Name == KeyName then
Tool:Destroy()
end
end
end