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

RemoteFunction not invoking?

Asked by 9 years ago

For reasons unknown to me, I compulsively use LocalScripts whenever theoretically possible. I'm using a LocalScript to make a digital clock, and so I'm needing to use a RemoteFunction, which is linked to a Script also inside the GUI, which returns the TimeOfDay as a string.

In Studio, the script(s) work perfectly and the clock works. However, in online mode, after a bit of testing, it appears that the LocalScript doesn't even invoke the RemoteFunction properly (I've tried using print(myFunction:InvokeServer()) and it returns nothing - no output, not even a "nil"). Does anyone know why this might be?

Scripts:

ClientManager (LocalScript)

coroutine.resume(coroutine.create(function() -- TimeLabel
    script.Parent.Parent.Frame.Frames.Main.TimeLabel.Text = script.Parent.ServerManager.GetServerTime:InvokeServer()

    script.Parent.ServerManager.GetServerTime.ServerTimeChanged.OnClientEvent:connect(function()
        script.Parent.Parent.Frame.Frames.Main.TimeLabel.Text = script.Parent.ServerManager.GetServerTime:InvokeServer()
    end)
end))

-- 3Tech
-- Do not redistribute!

ServerManager (Script)

local TimeStats = {
    last = tostring(game:GetService("Lighting").TimeOfDay),
    current = tostring(game:GetService("Lighting").TimeOfDay),
}

function script.GetServerTime.OnServerInvoke()
    return tostring(game:GetService("Lighting").TimeOfDay)
end

game:GetService("Lighting").Changed:connect(function(property)
    if tostring(property):lower() == "timeofday" then
        TimeStats.current = tostring(game:GetService("Lighting").TimeOfDay)

        if TimeStats.current ~= TimeStats.last then
            script.GetServerTime.ServerTimeChanged:FireClient(script.Parent.Parent.Parent.Parent)
        end
    end
end)

-- 3Tech
-- Do not redistribute!

Additionally, ServerTimeChanged is a RemoteEvent that is fired whenever the TimeOfDay is changed. I also hate using while loops. Again, I don't know why.

Many thanks.

0
Can't you just read TimeOfDay from the LocalScript? chess123mate 5873 — 9y

Answer this question