So I know this is probably easy, but I’m new to scripting. I have a door that can be opened using a key from the workspace. The key can be picked up by multiple people, so if I only removed it from one person’s backpack, everyone else would be stuck with the key still in their backpack. I want the key to get removed from everyone’s backpack when the door opens.
Here’s the server script inside of my door if you need it:
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)
for _, player: Player in ipairs(Players:GetPlayers()) do
if player.BackPack:FindFirstChild(toolName) or player.Character:FindFirstChild(toolName)
Tool:Destroy()
end
end
Alright so for some reason it’s still not getting deleted from the player’s backpack. Here’s my code now:
tool = workspace.Tools:WaitForChild("Key")
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))
local KeyName = "Key"
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
end
opened = true
debounce = false
end
end
end)