Easy solution is to put them into a folder, or even a model like you had last time would work. Let’s say this folder or model was called “Staircase”, and then you’d do a for i,v loop.
local staircase = game.Workspace:WaitForChild("Staircase")
for i,v in pairs(staircase:GetChildren()) do
CollectionService:AddTag(v, "testTag")
end
If you want multiple staircases, you could put multiple models into a folder, let’s say this folder was called “Staircases”
local staircases = game.Workspace:WaitForChild("Staircases")
for i, staircase in pairs(staircases:GetChildren()) do
for int, step in pairs(staircase:GetChildren())
CollectionService:AddTag(step, "testTag")
end
end
This way you can easily duplicate a staircase and paste in wherever you want and it’ll work just as usual. I’m not a fan of loops within loops, but considering this is only happening once, at the start of the game, it’s fine.
for i,n in pairs(CollectiveService:GetTagged("testTag")) do
n.Touched:Connect(function(hit)
local CanRun = true
n.CanCollide = true
n.Anchored = true
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid and CanRun then
CanRun = false
n.Transparency = 0.25
wait(.4)
n.Transparency = 0.5
wait(.4)
n.Transparency = 0.75
wait(.4)
n.Transparency = 1
n.CanCollide = false
print("It worked!")
wait(3)
if humanoid and CanRun == false then
CanRun = true
n.CanCollide = true
n.Transparency = 0
end
end
end)
end
I came to the conclusion that my for loop keeps reiterating as long as I step on it and I don’t know how to fix that.
I’m sorry for asking so many question, i’m just a little lost
At the start of every new function you always set CanRun to true, so it will always play out as if the debounce never happened, since every new iteration it restarts.
Simply put the local CanRun = true right before the n.Touched function, not at the start of it.
Yea I tried that later and work a little bit better but now every time I step on a new block it waits for the previous block to finish its transparency cycle then starts its own
What do you mean it’s appearing again? At the end of the function, you’re setting the part’s transparency back to 0. If this is not something you want, remove that line.
I basically wanna make it like the second one. But the problem with the second one is that all the parts have their own individual script, while the first one has one script in the ServerScriptStorage connected to all the bricks using CollectionService.
local TweenService = game:GetService("TweenService")
local CanRun = true
function triggered(part, otherPart)
local humanoid = otherPart.Parent:FindFirstChild("Humanoid")
if CanRun and humanoid then
CanRun = false
TweenService:Create(part, TweenInfo.new(1.2), {Transparency = 1}):Play()
wait(1.2)
part.CanCollide = false
wait(3)
CanRun = true
part.CanCollide = true
part.Transparency = 0
end
end
for i,n in pairs(CollectiveService:GetTagged("testTag")) do
n.CanCollide = true
n.Anchored = true
n.Touched:Connect(function(hit)
triggered(n, hit)
end)
end
There is no loop in this script. All that is happening is all the parts with a specific tag are iterated through and having all their Touched Events connected to the same function. That function must completely finish before it can be called again, because of the debounce.
If you want them all to be independent of one another, they must all have their own function.
Can’t CollectionService scripts not have all tags run simultaneously? I thought the whole point of them made it easier to give multiple parts a script without having to write one for every part.
They can all be connected to the same function, which is capable of running multiple times. The problem is adding a Debounce to that function only allows it to be running one time.