Simple car indicator script

Hi, i need to know how to make a simple indicator script for a - chassis.

You are being nowhere near as descriptive as you need to be, but from my best interpretation, you could put a highlight instance on the chassis whenever you need to indicate it.

What i need is a simple script for a part to go from smooth plastic to neon every 0.5 seconds for example. Something like that.

Make a new thread for the indicators which loops, then check when the key is pressed with UserInputService and start/stop the thread.

Sorry for no indents, on mobile rn

local TARGET_CHASSIS = workspace.[DIRECTORY]
while task.wait(0.5) do
if TARGET_CHASSIS.Material == Enum.Material.Neon then--Material currently neon, set to plastic
TARGET_CHASSIS.Material = Enum.Material.SmoothPlastic
else--Material is not neon, assume plastic and set to neon 
TARGET_CHASSIS.Material = Enum.Material.Neon
end
end
2 Likes

I tried adapting this script for what i wanted.
Tried it with this but didnt seem to work.

background = script.Parent.TextButton_Roundify_12px
right = script.Parent.Rightvalue.Value
lt = 1
script.Parent.MouseButton1Click:Connect(function()
	while task.wait(0.2) do
		if lt == 1 then
			lt = 2
			if right.Material == Enum.Material.SmoothPlastic then
				game:GetService("TweenService"):Create(background,TweenInfo.new(.3),{ImageColor3 = Color3.fromRGB(0, 0, 0)}):Play()
				right.Material = Enum.Material.Neon
				right.SpotLight.Enabled = true
			else
				game:GetService("TweenService"):Create(background,TweenInfo.new(.3),{ImageColor3 = Color3.fromRGB(36, 36, 36)}):Play()
				right.Material = Enum.Material.SmoothPlastic
				right.SpotLight.Enabled = false
			end
		else
			lt = 1
			game:GetService("TweenService"):Create(background,TweenInfo.new(.3),{ImageColor3 = Color3.fromRGB(36, 36, 36)}):Play()
			task.cancel()
		end
	end
end)

Again, unsure of what you want, code syntax seems mostly functional to me,

Replace task.cancel() with break or return

So. user clicks the gui button. The part starts flashing from smoothplastic to neon ever 0.2 seconds. And when the user clicks the button again. The flashing stops and it goes back to smooth plastic.

So now i’ve been trying and this is what ive got so far.
Only issue is after a second or two it just stops and doesnt wait until the user clicks the button again to cancel/break the while task loop.

background = script.Parent.TextButton_Roundify_12px
right = script.Parent.Rightvalue.Value
lt = 1

script.Parent.MouseButton1Click:Connect(function()
	if lt == 1 then
		lt = 2
		while task do
			game:GetService("TweenService"):Create(background,TweenInfo.new(.3),{ImageColor3 = Color3.fromRGB(0, 0, 0)}):Play()
			right.Material = Enum.Material.Neon
			right.SpotLight.Enabled = true
			wait(0.2)
			game:GetService("TweenService"):Create(background,TweenInfo.new(.3),{ImageColor3 = Color3.fromRGB(36, 36, 36)}):Play()
			right.Material = Enum.Material.SmoothPlastic
			right.SpotLight.Enabled = false
			if lt == 1 then
				task.cancel()
				break
	else
		lt = 1
		game:GetService("TweenService"):Create(background,TweenInfo.new(.3),{ImageColor3 = Color3.fromRGB(36, 36, 36)}):Play()
		right.Material = Enum.Material.SmoothPlastic
		right.SpotLight.Enabled = false
	end
		end
	end
end)

Alright, what the provided code was doing is cancelling it immediately after the first flash.

This should do more of what you’re looking for, you’ll just have to adapt it

local Enabled = false
local BreakEvent = Instance.new("BindableEvent") -- Doesn't need to be parented
OBJECT_.MouseButton1Click:Connect(function()
	if Enabled then
		BreakEvent:Fire() -- fires event to stop current loop
	else
		task.defer(StartLoop) -- Starts the loop in a separate thread
	end
	Enabled = not Enabled -- inverts the enabled signal
end)

function StartLoop()
	local continueLoop = true
	local ev;ev = BreakEvent.Event:Connect(function() -- Listens for break signal
		ev:Disconnect() -- Stops listening for a break signal
		continueLoop = false -- Creates a false condition for the 'while' loop, stopping it. May be able to swap out this method for task.cancel() but idk I've never used it
	end)

	while task.wait(0.2) and continueLoop do
		--Stuff
	end
end
1 Like

I can confirm that it is now working. Thank you very much for your help!

1 Like

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