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

Passing a function with :FireAllClients?

Asked by 6 years ago

What i am trying to achieve: Whenever i click a button, it runs a function for all clients.

Script in SSS:

game.ReplicatedStorage.RemoteEvent:FireAllClients()

Local Script in GUI:

local function clocks()
    while clock do
        game.Workspace.Value.Clock.Value = game.Workspace.Value.Clock.Value - 1
        sb.Frame.PC.Text = game.Workspace.Value.Clock.Value
        if game.Workspace.Value.Clock.Value == 0 then
            -- play sound
            break
        end
        wait(1)
    end
end
-- main
main.StartPC.MouseButton1Click:connect(function()
    if clock then return end
    clock = true
game.ReplicatedStorage.RemoteEvent.OnClientEvent:connect(function()
    clocks()
end)
end)

Any help?

1 answer

Log in to vote
0
Answered by
UgOsMiLy 1074 Moderation Voter
6 years ago

You would fire the server, and the server would fire all the clients.

Script

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player)
    game.ReplicatedStorage.RemoteEvent:FireAllClients()
end)

LocalScript

local function clocks()
    while clock do
        game.Workspace.Value.Clock.Value = game.Workspace.Value.Clock.Value - 1
        sb.Frame.PC.Text = game.Workspace.Value.Clock.Value
        if game.Workspace.Value.Clock.Value == 0 then
            -- play sound
            break
        end
        wait(1)
    end
end
-- main
main.StartPC.MouseButton1Click:Connect(function()
    if clock then return end
    clock = true
    game.ReplicatedStorage.RemoteEvent:FireServer() -- Fire the server
end)
game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function()
    clocks()
end)
0
It only runs it for 1 player instead of all players Brydell 0 — 6y
Ad

Answer this question