Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Sound keeps playing over and over again even after you die, how to fix?

Asked by 8 years ago

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)
0
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 dragonkeeper467 453 — 8y
0
There is no output to this. Sorry ragingskull182 67 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

For the first script is should be:

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 = true then --Add true
            Sound:Stop()
        end
    end
    wait(0.01)
end

For the second script it should be:

Character = script.Parent
Humanoid = Character.Humanoid

function Check()
while true do
    wait(0.1)
    if game.Lighting.Sound.IsPlaying = true then --Add true
        game.Lighting.Sound:Stop()
    end
end
end

Humanoid.Died:connect(Check)
game.Players.LocalPlayer.CharacterAdded:connect(Check)
Ad

Answer this question