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 import sound to specific players by using RemoteEvents?

I am trying to give a specific player a sound to play with RemoteEvents, but I don't really understand how to import the sound from the server script to the local script. This is what I have so far:

--LocalScript
local RepStorage = game.ReplicatedStorage:WaitForChild("RemoteEvent")

RepStorage.OnClientEvent:Connect(function(args)
	game.Workspace.ChaseTheme:Play()
end)


--ServerScript
local ReplicatedStorage = game.ReplicatedStorage:WaitForChild("RemoteEvent")

ReplicatedStorage:FireClient()


--Loop Players (LocalScript)
for _, r in pairs(game.Teams.Pearl:GetPlayers()) do
						
local RepStorage = game.ReplicatedStorage:WaitForChild("RemoteEvent")
	RepStorage.OnClientEvent:Connect(function()
		game.Workspace.ChaseTheme:Play()
	end)
end

4 comments

0

What do you mean loop of players

0

I edited my script. You can take a look there.

0

Then you would do FireClient(r). But, if you're doing it for every player, just use FireAllClients().

0

Ok. Thank you!

1 answer

✓ Accepted answer

First let's fix the misleading identifiers. Your variables are pointing to a remote event not the replicated storage.

Second you do not need the args parameter if you won't use it.

What the issue is, you need a player to fire to, or else how will roblox know who to work with? In this example I will get the player through PlayerAdded.

--LocalScript
local remote_event = game.ReplicatedStorage:WaitForChild("RemoteEvent")

remote_event.OnClientEvent:Connect(function()
	game.Workspace.ChaseTheme:Play()
end)




--ServerScript
local remote_event = game.ReplicatedStorage:WaitForChild("RemoteEvent")

game:GetService("Players").PlayerAdded:Connect(function(client)
	remote_event:FireClient(client) -- pass a player reference
end)

1 comment

0

What if it's in a loop of players? How would I approach to that?

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