I am trying to create a door that checks if a player has a tool in their inventory.
If they do, it open the door.
However, nothing happens when I touch the door, and no error are printed…
local allowedClasses = {"First Class"} --Add more classes here. Also, make sure that it is the tool name.
script.Parent.Touched:Connect(function(hit)
if not hit.Parent:FindFirstChild("Humanoid") then return end
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
for _,v in pairs(player.Backpack:GetChildren()) do
if v.Name == table.find(allowedClasses, v) then
script.Parent.CanCollide = false
wait(1)
script.Parent.CanCollide = true
end
end
end)
Should be
if table.find(allowedClasses,v.Name) then
Also you may need to also check if the player has an allowed class tool in their character as well since tools that are equipped are parented to your character
Nope, doesn’t work.
The new script is
local allowedClasses = {"First Class"} --Add more classes here. Also, make sure that it is the tool name.
script.Parent.Touched:Connect(function(hit)
if not hit.Parent:FindFirstChild("Humanoid") then return end
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
for _,v in pairs(player.Backpack:GetChildren()) do
if v.Name == table.find(allowedClasses, v.Name) then
script.Parent.CanCollide = false
wait(1)
script.Parent.CanCollide = true
end
end
for _,v in pairs(player.Character:GetChildren()) do
if v.Name == table.find(allowedClasses, v.Name) then
script.Parent.CanCollide = false
wait(1)
script.Parent.CanCollide = true
end
end
end)
And it still doesn’t print any errors.
What type of script is this and where is it located?
Maybe try this?
local allowedClasses = {"First Class"} --Add more classes here. Also, make sure that it is the tool name.
local function updateDoor()
script.Parent.CanCollide = false
wait(1)
script.Parent.CanCollide = true
end
script.Parent.Touched:Connect(function(hit)
local char = hit.Parent
local player = game.Players:GetPlayerFromCharacter(char)
if not player then return end
local tool = char:FindFirstChildOfClass("Tool")
if tool and table.find(allowedClasses,tool.Name) then
updateDoor()
return
else
for _,v in pairs(player.Backpack:GetChildren()) do
if not table.find(allowedClasses, v.Name) then continue end
updateDoor()
break
end
end
end)
Server script, located under the door.
test result:
Passed:
passed!
thanks so much!
1 Like
Does that mean it worked? If so, I recommend marking my post as the solution if it has helped you out!
If you have anymore issues don’t be afraid to make another post!