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

Variable won't change when client receives event?

Asked by
sssynk 58
4 years ago

I have the server firing all clients every second to change the value of a TextLabel on screen, and the intermissionTime variable changing every time the client is fired, but for some reason, the intermissionTime variable only changes once, to 29. My code is below. Thanks!

local timer = script.Parent
local intermissionTimer = game.ReplicatedStorage.Events.ChangeTimeIntermission

local intermissionTime = 30

intermissionTimer.OnClientEvent:Connect(function()

    local intermissionTime = intermissionTime - 1
    timer.Text = intermissionTime
    print("client: received server fired, time left is "..intermissionTime)

end)
0
Just add a while loop to get it to repeat. AlmostADemon 50 — 4y

1 answer

Log in to vote
0
Answered by
sssynk 58
4 years ago

It was me. For some reason, taking away the "local" on line 08 made it work.

0
The Variable was already defined. When you put `local` the variable gets defined. Putting no local will reference a variable that was already made like the "IntermissionTime" Variable you made up above in your script!!! <:D>! Tizzel40 243 — 4y
0
mark your question as Answered by Yourself Luka_Gaming07 534 — 4y
Ad

Answer this question