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

1P = script.Parent.Parent.Parent.Parent.Character.Humanoid
2while true do
3wait(0.1)
4if P.Health == 0 then
5script.Parent.Script.Static:play()
6wait(100)
7end
8wait()
9end

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.

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 
3game: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)
9end)
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:

1P = 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

Answer this question