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?
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'
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