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

I have a problem where the sound only works in studio not in game can anyone help?

Asked by
FPSVision -14
6 years ago

--Heres What My Script Is Basically About.

--So basically when someone health is 0 or when they die the sound is suppose to play -- but it doesn't for some reason. It works in studio not in game

P = script.Parent.Parent.Parent.Parent.Character.Humanoid 
while true do 
wait(0.1) 
if P.Health == 0 then 
script.Parent.Script.Static:play()
wait(100)
end
wait()
end 

Not sure what is wrong.

2 answers

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

Instead of using a while loop, use the Diedevent of humanoids.

As the event name implies, the code under the event will run when a humanoid dies.

Also, as Elite said, use :Play() with an uppercase P, not a lowercase p. Coding is case sensitive.

-- You used too many .Parent's so I shortened it out. Use a player added event so when the player and character load, we can get the character, its Humanoid, and play the sound.

game:GetService("Players").PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function(char)
        char.Humanoid.Died:Connect(function()
            script.Static:Play()
        end)
    end)
end)
Ad
Log in to vote
-1
Answered by 6 years ago

Your "play()" is lowercase, and this may cause an issue. You also can just use "script.Static" instead of "script.Parent.Script.Static" Try this:

P = script.Parent.Parent.Parent.Parent.Character.Humanoid

    while true do
        wait()
        if P.Health == 0 then
            script.Static:Play()
            wait(100)
        end
    end

Answer this question