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

LocalScript not receiving remoteEvent from Script?

Asked by 4 years ago

So I am trying to make an intermission script but for some reason, the countdown doesn't start. This is the server script.

game.Players.PlayerAdded:Connect(function(player)
    if Intermission.NewServer.Value == true then
        if Intermission.Timer:WaitForChild("LocalScript") then
            Intermission.NewServer.Value = false
            Intermission.Timer.Value = 30
            Intermission.IntermissionStart:FireAllClients()
        end
    end
end)

And the local script:

game.ReplicatedStorage.Intermission.IntermissionStart.OnClientEvent:Connect(function()
    for Timer = 30, 0, -1 do
        script.Parent.Timer.Value = script.Parent.Timer.Value - 1
        wait(1)
    end
end)
0
The FireAllClients function fires the RemoteEvent. OnClientEvent event for each client. ... Instead it will fire to all clients who have the same remote event connected to an OnClientEvent event. Since this function is used to communicate from the server to the client, it will only work when used in a Script . MattVSNNL 620 — 4y
0
The clients take longer than the server to load in, consider finding alternative methods or using the perfect solution by @imKirda down below. KadenBloxYT 135 — 4y

1 answer

Log in to vote
0
Answered by
imKirda 4491 Moderation Voter Community Moderator
4 years ago

PlayerAdded fires before the client even loads so the event is firing but the client and all the local scripts are not yet loaded thus they can't receive the signal.

Your solution would be instead of using PlayerAdded function, create new RemoteEvent and call it PlayerAdded and on client, when your local script runs, fire signal from the remote event to server that the client has loaded. That way you can be sure that client is loaded. Something like this:

Client

local Loaded = game:GetService('ReplicatedStorage').LoadedRemoteEvent -- your event

... some local code here

Loaded:FireServer()
--/Fires at the end of script and replaces PlayerAdded

Server

--/Same event from the local script code
local PlayerAdded = game:GetService('ReplicatedStorage').LoadedRemoteEvent

PlayerAdded.OnServerEvent:Connect(function(Client)
    print(Client) -- prints TheReverseGaming

    ... your script would be here
end
0
Ok I will try. TheReverseGaming 29 — 4y
Ad

Answer this question