Hey Guys,
I am having a bit of trouble using remote events, and I am trying to pass a clients sound ID they have inputted in a GUI element to the server and back to all clients to play a song on the whole server, using remote event arguments but I cannot seem to be able to pass any argument expect the player which is included by Roblox, and the server script only fires back to the client that sent the request and not all the other clients
/local side to the server
-- local side to server
local id = script.Parent.Parent.SoundID.Text
local remotes =
game:GetService("ReplicatedStorage"):WaitForChild("Requests"):WaitForChild("Server")
script.Parent.MouseButton1Click:Connect(function(player,id) -- when clicked
print(player)
print(id)
remotes:FireServer(player,id) -- fires the server with these arguments
end)
(I have added a few print statements to check if the sound ID has been passed through the local script to the server)
/server side to All clients
– to all clients from the server request
local remotes = game:GetService("ReplicatedStorage"):WaitForChild("Requests"):WaitForChild("Server")
local remotes2 =
game:GetService("ReplicatedStorage"):WaitForChild("Requests"):WaitForChild("Client")
remotes.OnServerEvent:Connect(function(player,id)
game.Workspace.ID.SurfaceGui.TextLabel.Text = id
print(id) -- checks to see if the ID went to the server
remotes2:FireAllClients(player,id) -- sends the ID back to ALL clients
end)
/all clients to play the ID from the server
local remotes2 = game:GetService("ReplicatedStorage"):WaitForChild("Requests"):WaitForChild("Client")
local sound = script.Parent.Client -- sound
remotes2.OnClientEvent:Connect(function(player,id) -- arguments from the server
print(id) -- checks to see if the ID has made it to all clients
wait(1)
sound:Stop()
sound.SoundId = "rbxassetid://"..id -- from the server
wait(0.04) -- small wait to load the asset
sound:Play() -- play same ID for all clients
end)
I wonder if there is another way to transfer a number value like an ID to the server and then back to all clients and how to pass arguments through a remote event and ending up on the server but when I tried it it just prints the ID as “nil” which does not play on the server and shows the argument has not been passed on to the server, I am not 100% sure that a remote event is needed here but it is only one-way communication and this is only needed to fire once because the all clients remote event will give feedback to all players including the player who fired the remote event to know that their song is on the whole server. Any suggestions on how I should do this would be greatly appreciated.