Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do i send Values from client to server?

Asked by 4 years ago

I'm trying to send a music ID using a GUI to a Sound Part in Workspace but as the gui is from the client and the part is on the server I need a remote event but I don't understand much of remote events ,does anyone know how I can inviate the ID to the workspace?

0
Remote Events raid6n 2196 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago
Edited by Leamir 4 years ago

You would need to use remote events, basically a remote event acts as a way for the server to interact with the client, and the client to interact with the server. You can find more info here on the ROBLOX Wiki page on the subject, https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events

For the client to communicate with the server, you need to place the remote where both the client and the server can access. Places like ServerStorage and ServerScriptService is a place where you do not want to place them as the client can not access any of those above services. A good place to put them is inside ReplicatedFirst or ReplicatedStorage

For client to server communication

local event = game.ReplicatedStorage:WaitForChild('RemoteEvent') --Replace with your event
local  var1 = 'yes'

event:FireServer(var1)

This will activate the event as soon as the game runs. You can send anything you want through remotes like var1 that I sent for example through remotes.

For server to client communication

local event = game.ReplicatedStorage:WaitForChild('RemoteEvent') --Replace with your event

game.Players.PlayerAdded:Connect(function(player) --For when the player joins
    event
    event:FireClient(player)
end

You must ALWAYS specify the player when you fire the client if you want it to fire to one specific client. If you would like to fire to all clients, you would need to use :FireAllClients()

If this helped you out please accept my answer, thank you!

EDIT: I forgot to add how you execute code when you fire it, my bad.

local event = game.ReplicatedStorage:WaitForChild('RemoteEvent') --Replace with your event

event.OnServerEvent:Connect(function(var1)
    print(var1)
end

The above is to connect to a server event, to connect to a client event, you would just do event.OnClientEvent. Above I sent var1 through the client to server, so the output should be 'yes'

0
Sorry if im late but it just printed my name not yes  focasing 0 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

thx for the code i fixed it becouse it send the plr so it was sending 2 values but your code only recived one and it was the player ,you need to make it recive the player name and the value ,you forgot to put ) in the end

local event = game.ReplicatedStorage:WaitForChild('RemoteEvent') --Replace with your event

event.OnServerEvent:Connect(function(var1)
    print(var1)
end

this is the fixed code

local event = game.ReplicatedStorage:WaitForChild('RemoteEvent') --Replace with your event

event.OnServerEvent:Connect(function(plr,var1) -- you need to put the plr first and then the value, i think you can use the values you want 
    print(var1)
end) -- i put the )

thx for the help and have a nice day if you want the code fixed you heve it here bye :3

Answer this question