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

How can i communicate from the client to the server?

How can i send a string as an example, from the client to the server?

P.S.: Not asking scripts, but preferably an explanation.

4 comments

0

Where would the string be stored?

0

Is there a way to get it and then store into a variable? Like using require with module scripts?

0

Try using remote events.

0

How can i send them with remote events?

1 answer

✓ Accepted answer

Remote Events/Functions.

Create a RemoteEvent in the ReplicatedStorage and you can pretty much interact with client/server boundaries.

local PrintString = game:GetService("ReplicatedStorage").PrintString

PrintString.OnServerEvent:Connect(function(Player,StringToSend)
	print(StringToSend)
end)

We have a remote event in the code above, and we make it so that everytime its fired we print the "StringToSend" parameter.

 game:GetService("ReplicatedStorage").PrintString:FireServer("test")

On a local script we fire it via remote event.

We can also do the same but with the server interacting with the client!

local TextLabel = script.Parent
local ChangeText =  game:GetService("ReplicatedStorage").ChangeText

ChangeText.OnClientEvent:Connect(funciton(Message)
	TextLabel.Text = Message
end)

We can then fire it using FireClient() or FireAllClients() (Fire client meaning fire to a specific player and fire all clients to fire for all players)

 game:GetService("ReplicatedStorage").ChangeText:FireClient(game.Players.Mr_Unlucky,"test")
game:GetService("ReplicatedStorage").ChangeText:FireAllClients("test")

1 comment

0

Thanks! I'll check if it works then i'll acept answer.

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