How to check a value when a part is touched

Hello! I am making a game where you have different levels and you need to beat, you have touch every collectible that’s in the level to pass to the next…

The problem is that, I have a block that you need to touch to pass to the next level and it checks if you have all of the collectibles. If you do it becomes green and if not then it becomes red. But it just don’t works and it has happened to me in multiple occations

This is the code for the part:

script.Parent.Touched:Connect(function()
	if game.ReplicatedStorage.LightValue.Value <= 5 then
		script.Parent.BrickColor = BrickColor.new("Really red")
	end
end)

script.Parent.Touched:Connect(function()
	if game.ReplicatedStorage.LightValue.Value >= 5 then
		script.Parent.BrickColor = BrickColor.new("Lime green")
	end
end)

Here’s a screenshot from studio:

image

I would appreciate some help!

They problem is that you cannot have two event listeners for the touched event! Instead, combine it into one:

script.Parent.Touched:Connect(function()
	if game.ReplicatedStorage.LightValue.Value < 5 then
		script.Parent.BrickColor = BrickColor.new("Really red")
	end
	if game.ReplicatedStorage.LightValue.Value >= 5 then
		script.Parent.BrickColor = BrickColor.new("Lime green")
	end
end)

I really hope this works for you! :slight_smile:

I doesn’t work, it’s still just in it’s original color

Oh I see its in a localscript. Can you try putting it in a normal script?

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.