I’m very new to scripting and I’m trying to make it so when a player touches a part, it plays music for only that player.
I noticed in my play testing that the music plays for all players.
I first put the sound in PlayerGui and later StarterPlayerScripts, but both do the same thing.
Here’s the script I’m using:
local debounce = false
function onTouched(part)
if not debounce then
debounce = true
game.Players.LocalPlayer.PlayerScripts.Music.Sky1:Play()
wait(1)
debounce = false
end
end
game.Workspace.MusicMaker5.Touched:connect(onTouched)
This script is a LocalScript and is located in StarterPlayerScripts. (Music is also located in StarterPlayerScripts in a model)
It plays the music as intended but the music plays for everyone.
I believe you should try to use PlayLocalSound, which will only play the sound locally to the specific client, try it out and see if it works. It’s a function of SoundService
local SoundService = game:GetService("SoundService")
local debounce = false
local function playLocalSound()
if not debounce then
debounce = true
local sound = SoundService.Start
SoundService:PlayLocalSound(sound)
wait(1)
debounce = false
end
end
game.Workspace.MusicMaker1.Touched:connect(playLocalSound)
It plays the music, but once again it plays for everyone.
I put this script in StarterPlayerScripts, and the music is in Soundscape.
The music will play for everyone because you’re not checking if the intersecting part comes from a character and if so, which player the character belongs to and if that player is the same as the LocalPlayer. This makes the sound end up being pseudoglobal.
I made a resource addressing this problem some time back: