How Do I Send Data To Server And Client For Excute?

I Been Making A System That Get Code From Server. And Excute On All Clients. Example: Create Button And Click It On Client Appeer A Text On Server. But Others Couldn’t See It. I Have Tried:

Code1
Button.Mouse1ButtonClick:Connect(function())
Instance.new("Hint", workspace).Text = "Hi"
end)
Code2
Button.Mouse1ButtonClick:Connect(function()
Instance.new("Hint", workspace).Text = "Hello"
end)
Code3
local Button = script.Button
Button.Mouse1ButtonClick:Connect(function(p)
Instance.new("Hint", workspace).Text = "Hi"
end)

I Tried Checking Button And Stuff.
The Button Is In StarterGui.Gui
And The Script Is Under Button.
None Of These Working. Please Help.

So None Of The Replies Working :c
I Still Working On It.

1 Like
4 Likes

So you add a remote event to ReplicatedStorage then you fire the remote event.

-- Client (local script)
path.to.remote:FireServer("funny string")
-- Script on the server (script)
path.to.remote.OnServerEvent:Connect(function(plr,message)
  Instance.new("Hint", workspace).Text = message
end)

or

You put the code you gave us in a server script.

1 Like

Uh. So. How Do I Excute From Server To Client In Plain?:
Like When Reiceve. It Send The Data To All Clients To Create The Text(For Performance Ig) In Plain Code?

As others have said, remote events are the way. Basically, you can fire the server from the client and send information. Just remember to always double check important data on the server, like how many coins to add.

Heres a good example of a remote event

local coinsToAdd = 5

button.MouseButton1Click:Connect(function()
event:FireServer(coinsToAdd)
end)

Then on the server:

event.OnServerEvent:Connect(function(plr, coinsToAdd)
plr.leaderstats.Coins.Value += coinsToAdd
end)

The way to make this safer is to always check the coins to add value on the server using an intvalue in replicated storage.

So make sure that coinsToAdd = CoinsIntValue.Value cause the client can fir whatever they want as coinsToAdd if theyre exploiters

first make event in replcated storage
image

then make script in server script service
code 01
game.ReplicatedStorage.event.OnServerEvent:Connect(function(player,text) Instance.new("Hint",workspace).Text = tostring(player).. "sent"..text end)
next use local script to send the text and the player who activated it
code 02
local text = "evil" script.Parent.TextButton.MouseButton1Up:Connect(function() game.ReplicatedStorage.event:FireServer(text) end)

I think you mean you want to send it all the clients from the server? I believe you can use :FireAllClients() with a remote event on the server.

1 Like

Why Are You Capitalizing Every Word

2 Likes

For client → server communication we often use remote events. Remote events are basically “doors” you open to the server, allowing the client to pass information through. However this information isn’t 100% trustworthy, it can be coming by an exploiter trying to gain an unfair advantage(just like a thief trying to break into your house). Therefore when you open such doors you need to always validate the data the client passes through on the server, basically check if the data is valid given your game/scripts behavior and ensure the client asking for something actually has the permission to do it.

The way we check is by taking advantage of the first default argument the server picks up, the player argument, that indicates which client fired the remote. This is the only piece of information we actually trust to make the checks.

depends on where the data is located

if you have the data on the server side, you can use it on the server then use :FireAllClients() or :FireClient (if you only need a specified player)

However, if the data is located on the client then you can send it to the server so that it processes the data then fires to all clients (if you want all the clients to use the data)

in all cases you should use a remote event for transporting data between server and client

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