Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

--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

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)

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

This discussion is preserved as it was. New answers, comments, and votes are closed.