Recently, I’ve started on my first actual game project, and I’ve ran into a few issues. Most of them I’ve been able to solve myself after a few minutes of googling or searching the DevForum, but this one I haven’t been able to figure out just yet, having spent over 48 hours in total trying to find out the solution:
I have a part set up so that when a player touches it, it blacks the screen out, plays a noise, teleports the player, and then fades the screen back in. So far, I have all of this working except the sound, which I want to play locally. I figured out I need to use a RemoteEvent to have it play for the local user only, so I started looking into how those work and how to use them. As far as I can tell, I seem to be doing everything right, but for whatever reason, the sound isn’t playing. I even set up ‘print’ statements in the LocalScript the event is meant to be triggering, to make sure it’s actually detecting the event, and it doesn’t seem to be.
As you can see, I have the event set up in ReplicatedStorage, along with a copy of the sound I want to play:
Here’s a few snippets from the script inside the trigger part, and the localscript, which is stored in StarterPlayerScripts:
Trigger part snippets
local players = game:GetService('Players') local PlayLocalSoundRemote = Instance.new('RemoteEvent', game.ReplicatedStorage) PlayLocalSoundRemote.Name = 'PlayLocalSoundRemote' function PlaySoundForPlayer(plr, SoundId) print("Running function.") for _,i in pairs(game.Players:GetPlayers()) do if i == plr then print("Player matches. Firing event.") PlayLocalSoundRemote:FireClient(plr,SoundId) print('Player is ' .. tostring(plr)) print('SoundId is ' .. tostring(SoundId)) end end end
Later on in the script, in the touchPart.Touched function:
local ReplicatedStorage = game:GetService('ReplicatedStorage') local playLocalSoundRemote = ReplicatedStorage:WaitForChild('PlayLocalSoundRemote') local function playSound(SoundId, Volume) print("got here") if Volume == nil then Volume = 1 end local Sound = Instance.new('Sound', workspace.CurrentCamera) Sound.SoundId = SoundId if not Sound.IsLoaded then Sound.Loaded:Wait() end Sound.Volume = Volume Sound:Play() print("Sound played.") game:GetService('Debris'):AddItem(Sound, Sound.TimeLength) end playLocalSoundRemote.OnClientEvent:Connect(playSound)
When testing, it seems to fire every single debug print in the trigger part’s script, but none of the print statements in the LocalScript, leading me to believe the localscript isn’t even detecting the event. Any help with this would be greatly appreciated.