Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How would I make this script work for the local player only?

local part1 = game.Workspace.oneMap.Portal.Portal
local sound1 = game:GetService("StarterPlayer").songTwo
local sound = game:GetService("StarterPlayer").songOne
part1.Touched:Connect(function(plr)
        local character = game.Players:GetPlayerFromCharacter(plr.Parent)
        local humanoid = plr.Parent:FindFirstChild("Humanoid")
        if humanoid then
        sound1:Play()
        if sound.IsPlaying then
            sound:Pause()
        else
            sound1:Play()
        end
    end
end)

I'm trying to make a speedrun game and make it to where every time a player touches the portal the music changes to something else. I want that to happen for the local player only. I have my local script in starterplayerscripts and my sounds in starterplayer.

1 answer

Soundservice has an function called PlayLocalSound for playing local sound. Instead of :Play() you would do game:GetService("SoundService"):PlayLocalSound(soundobject) replacing soundobject with your sound object of course. Pausing and stopping is the same, But you should make sure RespectFliteringEnabled is true in sound service.

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