✓ Accepted answer
The PlayerAdded function is totally unnecessary. If you want a sound to play on the client, then you should use RemoteEvents and FireClient() Also, if you're gonna use Instance.new() every single time, it will take resources and eventually cause a memory leak (Which is gonna break your game into nothing but spongecake.) Anyways, put a remote event in ReplicatedStorage and put a script under the part. As for the local script, you can put it anyways, but I suggest StarterPlayerScripts.
Server Script
local part = script.Parent
local remoteEvent = game.ReplicatedStorage.RemoteEvent
part.Touched:Connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr then
remoteEvent:FireClient(plr)
end
end)
Local Script
local remoteEvent = game.ReplicatedStorage.RemoteEvent
local sound = game.ReplicatedStorage.Sound
remoteEvent.OnClientEvent:Connect(function()
sound:Play()
end)
3 comments
Is this a local script?
Why would it be? It's a server script.
check again if the soundId matches the link