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

This script wont work. What did I do wrong?

It's where if the part is transparent, it does no damage, but if it's opaque, it kills you instantly. I don't know what I did wrong.

while true do
	wait(10)
	script.Parent.Transparency = 1
	wait(10)
	script.Parent.Transparency = 0
	



function onTouched (part)
	if part.Transparency == 0 then
              local h = script.Parent.Parent:findFirstChild ("Humanoid")
              h.Health = 0
              end
end
end
script.Parent.Touched:connect(onTouched)


5 comments

0

Trying putting the while loop in another script. While you can get this working in one script if you tried hard enough, it would just be easier having two separate scripts...

0

Alright. Thanks. c:

0

Still doesn't kill.

0

Capitalization issue...FindFirstChild(). You did not capitalize the 'f' in First

0

Oh. Thanks! :)

1 answer

This should work:

script.Parent.Touched:connect(function(hit)
	humanoid = hit.Parent:findFirstChild("Humanoid")
	if(humanoid ~= nil and script.Parent.Transparency == 0) then
		humanoid.Health = 0
	end
end)

What I am doing is checking if a Humanoid exists and that the part is not transparent, if so, kill the player who touched the block, if not, do nothing.

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