How can i send a string as an example, from the client to the server?
P.S.: Not asking scripts, but preferably an explanation.
How can i send a string as an example, from the client to the server?
P.S.: Not asking scripts, but preferably an explanation.
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")
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.
4 comments
Where would the string be stored?
Is there a way to get it and then store into a variable? Like using require with module scripts?
Try using remote events.
How can i send them with remote events?