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

My script is ignoring parts in workspace?

Asked by
uhTeddy 101
6 years ago

So i have game.Workspace.StaffDoor but when I type S nothing shows up, so I though, Okay then lets do game.Workspace:FindFirstChild("StaffDoor") I tested it an the script didn't work the way it did in the other game I created with less parts. Is there a way to fix this?

0
Please give us the full script User#17125 0 — 6y
0
Please explain it more. What is the script supposed to do? What is it doing? and if it's possible paste your script here personal_ly 151 — 6y
0
Probably an Only Door for staffs... thesit123 509 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

You should explain in more detail what you mean in future questions:

  • What does typing "S" do? How?
  • What do you mean by "less parts"?
  • What do you mean "nothing shows up" - are you trying to print something, is a gui supposed to show up, what?

I'm guessing that your problem is that you have multiple StaffDoors and your script is only set up to work with one. If my guess is correct, you'll need to iterate over all the workspace's children, rather than use FindFirstChild (which only finds the "first child", as the name suggests).

--Instead of:

function OnTouch(part)
    -- function contents here
end
workspace.StaffDoor.Touched:Connect(OnTouch)


--You need:

function OnTouch(door, part)
    --use 'door' instead of 'workspace.StaffDoor'; otherwise, function contents may be the same
end
local ch = workspace:GetChildren()
local door
for i = 1, #ch do
    door = ch[i]
    door.Touched:Connect(function(part) OnTouch(door, part) end)
end
Ad

Answer this question