Local Script not being local

  1. I’m trying to make my local script actually be local.

  2. When a player touches any of the parts that trigger the script, it affects every player.

  3. I tried looking at the forum for about half an hour, didn’t help.

Before you ask, yes, it works perfectly fine, the ONLY issue is that it runs for every player.

local Default = game.workspace.MusicSaves:WaitForChild("DefaultMusic")
local DefaultPlaylist = game.workspace.MusicSaves.Default:getChildren()
local Underground = game.workspace.MusicSaves:WaitForChild("UndergroundMusic")
local UndergroundTrack = game.workspace.MusicSaves.Underground
local birds = game.workspace.Misc.AmbientBirds
local sea = game.workspace.Misc.SeaAmbience

--default
Default.Touched:Connect(function()
	game.workspace.MusicSaves.Default.PlaybackSpeed = 1
	DefaultPlaylist.PlaybackSpeed = 1
	game.workspace.MusicSaves.Default.Script.Enabled = true
	UndergroundTrack.PlaybackSpeed = 0
	game.workspace.Misc.AmbientBirds.PlaybackSpeed = 1
	game.workspace.Misc.SeaAmbience.PlaybackSpeed = 1
end)

--underground
Underground.Touched:Connect(function()
	game.workspace.MusicSaves.Default.PlaybackSpeed = 0
	DefaultPlaylist.PlaybackSpeed = 0
	game.workspace.MusicSaves.Default.Script.Enabled = false
	UndergroundTrack.PlaybackSpeed = 1
	birds.PlaybackSpeed = 0
	sea.PlaybackSpeed = 0
	
end)

Note: This was my first Local Script, I made a test script and was able to confirm that properties can be changed locally, so I don’t know why this doesn’t work.

Well because the script is added each time the client enters the game? You’re just connecting it for each client, not even checking if its a player nor the player that touched the part.

Try this:

local Default = workspace.MusicSaves:WaitForChild("DefaultMusic")
local DefaultPlaylist = workspace.MusicSaves.Default:getChildren()
local Underground = workspace.MusicSaves:WaitForChild("UndergroundMusic")
local UndergroundTrack = workspace.MusicSaves.Underground
local birds = workspace.Misc.AmbientBirds
local sea = workspace.Misc.SeaAmbience

--default
Default.Touched:Connect(function(otherPart : Part)
	if not otherPart.Parent:FindFirstChildOfClass("Humanoid") then return end
	if otherPart.Parent.Name ~= game.Players.LocalPlayer.Name then return end

	workspace.MusicSaves.Default.PlaybackSpeed = 1
	DefaultPlaylist.PlaybackSpeed = 1
	workspace.MusicSaves.Default.Script.Enabled = true
	UndergroundTrack.PlaybackSpeed = 0
	workspace.Misc.AmbientBirds.PlaybackSpeed = 1
	workspace.Misc.SeaAmbience.PlaybackSpeed = 1
end)

--underground
Underground.Touched:Connect(function(otherPart : Part)
	if not otherPart.Parent:FindFirstChildOfClass("Humanoid") then return end
	if otherPart.Parent.Name ~= game.Players.LocalPlayer.Name then return end
	
		workspace.MusicSaves.Default.PlaybackSpeed = 0
		DefaultPlaylist.PlaybackSpeed = 0
		workspace.MusicSaves.Default.Script.Enabled = false
		UndergroundTrack.PlaybackSpeed = 1
		birds.PlaybackSpeed = 0
		sea.PlaybackSpeed = 0
end)

Yeah I do see it now, it also works! Thanks!

1 Like