The parts in the model won't go transparent

So sinced I named them all differently, for every new part I have do I have to make a new variable for them in the CollectiveService script like so:

local EventTriggered2 = game.Workspace:FindFirstChild("EventTriggered2")
local EventTriggered3 = game.Workspace:FindFirstChild("EventTriggered3")
local EventTriggered4 = game.Workspace:FindFirstChild("EventTriggered4")
local EventTriggered5 = game.Workspace:FindFirstChild("EventTriggered5")
local EventTriggered6 = game.Workspace:FindFirstChild("EventTriggered6")

CollectiveService:AddTag(EventTriggered2, "testTag")
CollectiveService:AddTag(EventTriggered3, "testTag")
CollectiveService:AddTag(EventTriggered4, "testTag")
CollectiveService:AddTag(EventTriggered5, "testTag")
CollectiveService:AddTag(EventTriggered6, "testTag")

Would I have to keep copying it if I wanted to add more parts?

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 some reason my debounce statement won’t work.

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

also thanks for the above code

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

Ah, I see. Try disabling the debounce entirely?

Now everytime it’s hit it keeps appearing again. Probably because of the loop?

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.

robloxapp-20210306-0033284.wmv (2.9 MB)

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.

So like

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

For some reason it’s doing the same thing
robloxapp-20210306-0150533.wmv (1.9 MB)
Is it probably because of the for loop?

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.

I took off the debounce in the if statement and it worked just now
robloxapp-20210306-0157329.wmv (2.1 MB)
Thank You!

2 Likes

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.

Ah I see now, makes enough sense.

1 Like