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

Passing a function with :FireAllClients?

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

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)

1 comment

0

It only runs it for 1 player instead of all players

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