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

What is wrong with this script? (Sound played on damage)

It's my first time writing a script from scratch, but it wont work, and I get an error. Any idea on how to fix? This is will be used for my Serious Sam game, by the way.

function() findfirstchild(Humanoid)
	if humanoid.Health = -50 -- If the player looses 50 health, then the sound in the script will play only for a split second.
		then
		sound3:(play)
		wait(0.5)
		sound3:(stop)
	end
end


if findfirstchild(Humanoid)
	if humanoid.Health = -25
		then
		sound2:(play)
			sound2:(play)
		wait(0.5)
		sound2:(stop)
	end
end


if findfirstchild(Humanoid)
	if humanoid.Health = -10
		then
		sound1:(play)
			sound1:(play)
		wait(0.5)
		sound1:(stop)
	end
end


if findfirstchild(Humanoid)
	if humanoid.Health = -75
		then
		sound4:(play)
			sound3:(play)
		wait(0.5)
		sound4:(stop)
	end
end

1 answer

✓ Accepted answer

If the if ___ then statement you need a "==" or "~="(Only for some things though.) Don't forget... You need to put little, "Variables" (I think it's called) for example...

sound1 = game.Workspace.Death--Or players or soundscape...

Also Function by its self won't work.

function onTouch(part) -- Lava
local humanoid = part.Parent:FindFirstChild("Humanoid") 
if (humanoid ~= nil) then
humanoid.Health = 0
end 
end
script.Parent.Touched:connect(onTouch)

I fixed some of it. I don't know If you want it too scan or anything...

function()
findfirstchild(Humanoid)
if humanoid.Health == -50 then
sound3:(play)
wait(0.5)
sound3:(stop)
end
end
if findfirstchild(Humanoid)
if humanoid.Health == -25 then
sound2:(play)
wait(0.5)
sound2:(stop)
end
end
if findfirstchild(Humanoid)
if humanoid.Health == -10 then
sound1:(play)
wait(0.5)
sound1:(stop)
end
end
if findfirstchild(Humanoid)
if humanoid.Health == -75 then
sound4:(play)
wait(0.5)
sound4:(stop)
end
end

4 comments

0

Yes. I want it to scan for a change in the Humanoid's health.

0

Yes but you also have other mistakes in your script too. You can go to wiki if it helps.

0

Hmm...I don't know how to program it, though. It's my first script. lol

0

I see... Here look at this link, see if it helps. http://wiki.roblox.com/index.php?title=Function_Dump

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