I wanted the sound to play once the player torso's distance is close by the noob and stop when the player's distance is too far.
local player = game.Players.LocalPlayer local noob = game.Workspace.NoobStand.Noob local song = Instance.new('Sound',player.PlayerGui) song.SoundId = 'rbxassetid://302095292' song.Volume = 1 song.Looped = true while wait() do local magnitude = (noob.Torso.Position - player.Character.Torso.Position).magnitude if magnitude < 6 then song:Play() print("Enter") elseif magnitude > 6 then print("Exit") song:Stop() end end
No errors in output.
I think that you should try using WaitForChild because I have a feeling the character isn't loading when this runs. Try this:
local player = game.Players.LocalPlayer local Character = Player.Character or Player.CharacterAdded:wait() local Torso = Character:WaitForChild("Torso") local noob = game.Workspace.NoobStand.Noob local song = Instance.new('Sound',player.PlayerGui) song.SoundId = 'rbxassetid://302095292' song.Volume = 1 song.Looped = true while wait() do local magnitude = (noob.Torso.Position - Torso.Position).magnitude if magnitude < 6 then song:Play() print("Enter") elseif magnitude > 6 then print("Exit") song:Stop() end end