--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
1 | P = script.Parent.Parent.Parent.Parent.Character.Humanoid |
2 | while true do |
3 | wait( 0.1 ) |
4 | if P.Health = = 0 then |
5 | script.Parent.Script.Static:play() |
6 | wait( 100 ) |
7 | end |
8 | wait() |
9 | end |
Not sure what is wrong.
Instead of using a while loop, use the Died
event 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.
1 | -- 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. |
2 |
3 | game:GetService( "Players" ).PlayerAdded:Connect( function (plr) |
4 | plr.CharacterAdded:Connect( function (char) |
5 | char.Humanoid.Died:Connect( function () |
6 | script.Static:Play() |
7 | end ) |
8 | end ) |
9 | end ) |
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:
1 | P = script.Parent.Parent.Parent.Parent.Character.Humanoid |
2 |
3 | while true do |
4 | wait() |
5 | if P.Health = = 0 then |
6 | script.Static:Play() |
7 | wait( 100 ) |
8 | end |
9 | end |