So I'm making an AI with a magnitude script that plays music when he chases you. The problem is, when you respawn for some reason, the music starts as if you entered the vicinity of the enemy and it does that every time except for the first time. Can someone please help me fix this? Thanks!
Here are the two scripts that people helped me make:
local part1 = game.Workspace.Neighbor.Torso --The torso of your AI
local player = game.Players.LocalPlayer --Gets the player
local part2 = game.Workspace:WaitForChild(player.Name):WaitForChild("Torso") --The player
local Sound = game.Lighting.Sound --Your Sound, place in PlayerGui for local sound instead of global
while true do
local magnitude = (part1.Position - part2.Position).magnitude
if magnitude < 50 then
if not Sound.IsPlaying then
Sound:Play()
end
elseif magnitude >= 50 or game.Workspace:FindFirstChild(player.name):FindFirstChild("Torso") then
if Sound.IsPlaying then
Sound:Stop()
end
end
wait(0.01)
end
Character = script.Parent
Humanoid = Character.Humanoid
function Check()
while true do
wait(0.1)
if game.Lighting.Sound.IsPlaying then
game.Lighting.Sound:Stop()
end
end
end
Humanoid.Died:connect(Check)
game.Players.LocalPlayer.CharacterAdded:connect(Check)

2 comments
Any output? To view output window simply click on View at the top of studio and click on the output button displayed below that toolbar
There is no output to this. Sorry