So, just for some context, I'm making a car wash. At the beginning of the car wash, there's a signal. By default, it displays "Please Move Forward", indicating the car should go forward. But when the car is in a signal brick (basically, when the car is on the conveyor moving into the wash), it says "Please Wait", indicating to the car behind it that it should wait before moving forward.

I currently have a working version, but it doesn't work the best.

-- Setting variables
touchMeBrick = script.Parent
signalBrick = game.Workspace.GoStopSignal.signalGoStop
greenLight = game.Workspace.GoStopSignal.GreenLight
yellowLight = game.Workspace.GoStopSignal.YellowLight
redLight = game.Workspace.GoStopSignal.RedLight

-- Onstart functions
redLight.SurfaceLight.Brightness = 0
yellowLight.SurfaceLight.Brightness = 0

-- On touch, make the brick red and the decal "Please Wait"
touchMeBrick.Touched:connect(function(part)
	wait(.1)
	redLight.Transparency = 0
	redLight.SurfaceLight.Brightness = 5
	yellowLight.Transparency = 0.5
	yellowLight.SurfaceLight.Brightness = 0	
	greenLight.Transparency = 0.5
	greenLight.SurfaceLight.Brightness = 0
	signalBrick.BrickColor = BrickColor.new(21)
	signalBrick.Decal.Texture = "http://www.roblox.com/asset/?id=686944119"
end)

-- On touch, make the brick green and the decal "Please Move Forward"
touchMeBrick.TouchEnded:connect(function(part)
	yellowLight.Transparency = 0
	redLight.Transparency = 0.5
	greenLight.SurfaceLight.Brightness = 0
	yellowLight.SurfaceLight.Brightness = 5	
	redLight.SurfaceLight.Brightness = 0
	wait(15)

	-- Changes brick colour back to green when there is no car in the queue, indicating to go
	greenLight.Transparency = 0
	yellowLight.Transparency = 0.5
	greenLight.SurfaceLight.Brightness = 5
	yellowLight.SurfaceLight.Brightness = 0	
	redLight.SurfaceLight.Brightness = 0
	signalBrick.BrickColor = BrickColor.new(37)
	signalBrick.Decal.Texture = "http://www.roblox.com/asset/?id=686935976"
end)

It will change the color and decal on touch, but it's kind of buggy. It'll change back to green even if I'm standing inside the brick (it's at least 20 x 20 studs) and even when a car is inside it. I should point out that it only happens when I remove the

wait(15)

In the second function. I put it there originally to try and help with the problem, but it's not really a good fix.

Are there any functions better than onTouch and TouchEnded, or a better way to detect whether or not something is inside?? Any help would be greatly appreciated!

1 comment