Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

LocalScript not receiving remoteEvent from Script?

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)

2 comments

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 .

0

The clients take longer than the server to load in, consider finding alternative methods or using the perfect solution by @imKirda down below.

1 answer

✓ Accepted answer

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

1 comment

0

Ok I will try.

This discussion is preserved as it was. New answers, comments, and votes are closed.