local checkpointsFolder = game.Workspace.CheckpointsFolder
print("Script Running")
for i, v in pairs(checkpointsFolder:GetChildren()) do
v.Touched:Connect(function()
print("hi")
end)
end
Try adding a IsA method when checking for each children, to check whether the child is a part.
So, the script should be something like this:
for i, v in pairs (checkpointsFolder:GetChildren()) do
if v.IsA(“Part”) then -- checking whether the child is a part
v.Touched:Connect(function()
print("hi")
end)
end
end
Also the local script is in starter player, Is that correct?
EDIT: it only works in starter player after I play the game, then reset then it works. So then I tried to add a 5 second wait at the first line of the script cause maybe something is loading in faster than its supposed to, apparently it works now.
Something is loading in too fast. What would it be?
EDIT: I added a simple wait() at the very beginning and now everything works
EDIT: NOW WHEN I ADD SOUND EVERYTHING BREAKS AUGHH
Instead of doing wait(), try doing game.Players.LocalPlayer.CharacterAdded:Wait(), this is a little better than wait() as that doesn’t insure the character has actually loaded in and it still might bug, also please mark your post as solved
It doesn’t have anything to do with the character because he isn’t using any code that needs the character. The code is just running before the checkpoints folder is loading in.
Okay, there is another problem, everything works fine but when I add Sound:Play() it would work the first few times then the script would just break and the other parts dont even turn green and or play any sound
here is my code:
game.StarterPlayer.StarterCharacterScripts:WaitForChild("Checkpoints")
game.StarterPlayer.StarterCharacterScripts.Checkpoints:WaitForChild("Sound")
game.Workspace:WaitForChild("CheckpointsFolder")
local sound = script:WaitForChild("Sound")
local checkpointsFolder = game.Workspace:WaitForChild("CheckpointsFolder")
local green = BrickColor.new("Lime green")
for i, v in pairs(checkpointsFolder:GetChildren()) do
v.Touched:Connect(function()
if v.BrickColor == green then
print("Already green")
else
v.BrickColor = BrickColor.new("Lime green")
sound:Play()
end
end)
end