Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

So I've been trying to make a clock using a remote event, why wont the script work?

Normal Script the one that fires the remote event

local TimerStart = Instance.new("RemoteEvent")
	TimerStart.Parent = game.ReplicatedStorage
	TimerStart.Name = "TimerStart"

function onTouch()
print("working")
TimerStart:FireClient()
end
		
	
script.Parent.Touched:connect(onTouch)

local script the one that runs the timer

	local time = 0
	local function TimerStart()
print("working2")
script.Parent.Parent.TextLabel.Text = 0
for i = 1, 9999 do
	wait(0.1)
	time = time + 0.1
 script.Parent.Parent.TextLabel.Text = tostring(time)
	

end
end

Heres the new updated local script

	local time = 0
	local function TimerStart()
print("working2")
script.Parent.Parent.TextLabel.Text = 0
for i = 1, 9999 do
	wait(0.1)
	time = time + 0.1
 script.Parent.Parent.TextLabel.Text = tostring(time)
	
TimerStart.OnClientEvent:Connect(TimerStart)

end
end

2 comments

0

You need to use TimerStart.OnClientEvent. The function in your local script isn’t being called.

0

"time" is a global function built in by rblx, rename time to something else as it can confuse the script.

1 answer

✓ Accepted answer

Looks like you're missing an OnClientEvent in your Local Script. Should also rename your event so it's not the same as your function.

Local Script

TimerStart.OnClientEvent:Connect(TimerStart)

Also, specify which client to start the timer. Server Script

TimerStart:FireClient(player)

Here is what you should have:

Local Script

local event = game:GetService("ReplicatedStorage"):WaitForChild("TimerStart")
local time = 0

local function TimerStart()
	print("working2")
	script.Parent.Parent.TextLabel.Text = 0

	for i = 1, 9999 do
	    wait(0.1)
	    time = time + 0.1
	    script.Parent.Parent.TextLabel.Text = tostring(time)
	end
end

event.OnClientEvent:Connect(TimerStart)

Server Script

local TimerStart = Instance.new("RemoteEvent")
    TimerStart.Parent = game.ReplicatedStorage
    TimerStart.Name = "TimerStart"

function onTouch(hit)
	print("working")	
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if player then 
		TimerStart:FireClient(player)
	end	
end

script.Parent.Touched:Connect(onTouch)

11 comments

0

Although this does help, I get an error on normal script saying "Argument 1 missing or nil" anyway I can fix this?

0

Yeah, figured something was missing. Just updated the answer.

0

Hopefully you know how to find a player from a touch event?

0

Did he also forget about the Player Gui? Or no?

0

The local script still doesn't work, the new one is updated in the question, did i do something wrong?

0

@IAmSoloz it goes outside the function

0

LocalScript:1: attempt to index global 'TimerStart' (a nil value)

0

It's nil because you didn't declare TimerStart and it should really be named something else. Updated answer with what you should have.

1

Thank you so much it works!

0

@MCAndRobloxUnited No, the local script is already referencing the TextLabel so I can assume it's inside the GUI.

0

oof, i thought so

This discussion is preserved as it was. New answers, comments, and votes are closed.