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

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
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

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)
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