Remote Event only works once

As the title says, the remote event isn’t properly working. I’m trying to make a script where whenever I hit a button the part changes to blue and after 5 seconds the part changes to red only to me (the client). Everything works fine the first time but when I try clicking the button again the remote event just doesn’t work again. Here are the scripts:
LocalScript

local partColor = part.Color

local tf = true

script.Parent.Activated:Connect(function()
	if tf == true then
		game:GetService("ReplicatedStorage").RemoteEvent:FireServer()
		wait(5)
		part.Color = partColor
		tf = false
	end
end)

EventScript


local RE = game:GetService("ReplicatedStorage").RemoteEvent

RE.OnServerEvent:Connect(function(player)
	if player then
		part.Color = Color3.fromRGB(0, 166, 255)
	end
end)
2 Likes
script.Parent.Activated:Connect(function()
	if tf == true then
        part.Color = Color3.fromRGB(0, 166, 255)
		game:GetService("ReplicatedStorage").RemoteEvent:FireServer()
		wait(5)
		part.Color = partColor
		tf = false
	end
end)

probably won’t work but it might

Tried the code, it didn’t work.

you need to set tf to true (char)

1 Like

Don’t you want:

The way you have it, tf gets set false after 5 seconds and nothing can ever make it true again, you want it false only during the 5-second cooldown.

2 Likes

This is happening because tf’s value is set to false which won’t make it work anymore after the first activation. This happens because the script disables it at the end and doesn’t reactivate it at the next click.

EmilyBendsSpace’s solution should work perfectly fine. mark her reply as the solution if it works, which it should hopefully.

1 Like

I just realized my mistake, will try to fix the code and run it again.

1 Like

Just fixed the code where the event atarts tf is equaled to false then after 5 second tf is equaled to true again. Thanks for the help!

1 Like

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