How To Get Code From The Server To Execute On All Clients

I’ve made something that when you press a button, it sends code to the server and executes it (I’m aware of how exploiters can get around this but it doesnt matter). I basically need it to fire that code to everyone in the game. As it is the server, it should however this is to do with GUI’s and it requires LocalPlayer to run.

I’ve tried using FireAllClients But it still seems to fire from the server. Anyway to fix this?

Code:
Code For Sending To Server (Works)

script.Parent.MouseButton1Click:Connect(function()
	game.ReplicatedStorage.Remotes.ExecuteAnnounce:FireServer(tostring(script.Parent.Parent.AnnouncementCod.Text) )
	print(tostring(script.Parent.Parent.Code.Text))
end)

Code For Sending To All Clients: (Works But Runs Code On Server)

local function Exe(Code,Acc)

	local stuff = loadstring(Acc)()
	game.ReplicatedStorage.Remotes.ExecuteAnnounce:FireAllClients(stuff)
end


game.ReplicatedStorage.Remotes.ExecuteAnnounce.OnServerEvent:Connect(Exe)

If there is an obvious problem in my code, please point it out.

Sorry. I’m a bit confused. What are you trying to do? what is your goal? Is it to make it all client side, but send for all clients?

Basically I don’t know if you’ve seen the HD Admin call - out screen? For example it shows a gui for everyone on the screen by executing code. That’s basically what im trying to do.

Basically getting code from 1 client / the server to all clients

you cannot send client data to server like script.Parent.Text (from client).
You can fix it by using RemoteFunction.
Tutorials:

Fixed Code Client:

game.ReplicatedStorage.RemoteFunction.OnClientInvoked:Connect = function()
print(tostring(script.Parent.Parent.AnnouncementCod.Text))
return tostring(script.Parent.Parent.AnnouncementCod.Text)
end
script.Parent.MouseButton1Click:Connect(function()
	game.ReplicatedStorage.Remotes.ExecuteAnnounce:FireServer(game.Players.LocalPlayer)
end)

Server Code:

local function Exe(Acc)

	local stuff = game.ReplicatedStorage.RemoteFunction:InvokeClient(Acc)
    loadstring(stuff)()
	game.ReplicatedStorage.Remotes.ExecuteAnnounce:FireAllClients(stuff)
end


game.ReplicatedStorage.Remotes.ExecuteAnnounce.OnServerEvent:Connect(Exe)

I’ll try it in a second, Thanks Anyways

dont forget to add

game.ReplicatedStorage.Remotes.ExecuteAnnounce.OnClientEvent

to work

game.ReplicatedStorage.Remotes.ExecuteAnnounce:FireAllClients(stuff)

StringLoader.rbxm (65.4 KB)
Using this module, you can run code on the clients.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.