Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago
Edited 6 years ago

Normal Script the one that fires the remote event

01local TimerStart = Instance.new("RemoteEvent")
02    TimerStart.Parent = game.ReplicatedStorage
03    TimerStart.Name = "TimerStart"
04 
05function onTouch()
06print("working")
07TimerStart:FireClient()
08end
09 
10 
11script.Parent.Touched:connect(onTouch)

local script the one that runs the timer

01    local time = 0
02    local function TimerStart()
03print("working2")
04script.Parent.Parent.TextLabel.Text = 0
05for i = 1, 9999 do
06    wait(0.1)
07    time = time + 0.1
08 script.Parent.Parent.TextLabel.Text = tostring(time)
09 
10 
11end
12end

Heres the new updated local script

01    local time = 0
02    local function TimerStart()
03print("working2")
04script.Parent.Parent.TextLabel.Text = 0
05for i = 1, 9999 do
06    wait(0.1)
07    time = time + 0.1
08 script.Parent.Parent.TextLabel.Text = tostring(time)
09 
10TimerStart.OnClientEvent:Connect(TimerStart)
11 
12end
13end
0
You need to use TimerStart.OnClientEvent. The function in your local script isn’t being called. andrewcooke582 -52 — 6y
0
"time" is a global function built in by rblx, rename time to something else as it can confuse the script. User#19524 175 — 6y

1 answer

Log in to vote
2
Answered by 6 years ago
Edited 6 years ago

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

1TimerStart.OnClientEvent:Connect(TimerStart)

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

1TimerStart:FireClient(player)

Here is what you should have:

Local Script

01local event = game:GetService("ReplicatedStorage"):WaitForChild("TimerStart")
02local time = 0
03 
04local function TimerStart()
05    print("working2")
06    script.Parent.Parent.TextLabel.Text = 0
07 
08    for i = 1, 9999 do
09        wait(0.1)
10        time = time + 0.1
11        script.Parent.Parent.TextLabel.Text = tostring(time)
12    end
13end
14 
15event.OnClientEvent:Connect(TimerStart)

Server Script

01local TimerStart = Instance.new("RemoteEvent")
02    TimerStart.Parent = game.ReplicatedStorage
03    TimerStart.Name = "TimerStart"
04 
05function onTouch(hit)
06    print("working")   
07    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
08    if player then
09        TimerStart:FireClient(player)
10    end
11end
12 
13script.Parent.Touched:Connect(onTouch)
0
Although this does help, I get an error on normal script saying "Argument 1 missing or nil" anyway I can fix this? IAmSoloz 14 — 6y
0
Yeah, figured something was missing. Just updated the answer. MooMooThalahlah 421 — 6y
0
Hopefully you know how to find a player from a touch event? MooMooThalahlah 421 — 6y
0
Did he also forget about the Player Gui? Or no? DeceptiveCaster 3761 — 6y
View all comments (7 more)
0
The local script still doesn't work, the new one is updated in the question, did i do something wrong? IAmSoloz 14 — 6y
0
@IAmSoloz it goes outside the function MooMooThalahlah 421 — 6y
0
LocalScript:1: attempt to index global 'TimerStart' (a nil value) IAmSoloz 14 — 6y
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. MooMooThalahlah 421 — 6y
1
Thank you so much it works! IAmSoloz 14 — 6y
0
@MCAndRobloxUnited No, the local script is already referencing the TextLabel so I can assume it's inside the GUI. MooMooThalahlah 421 — 6y
0
oof, i thought so DeceptiveCaster 3761 — 6y
Ad

Answer this question