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

(not answered)Im trying to make a kill brick for the hostiles, help me please?

Lua keeps saying unexpected error "=" or it not a correct statement "then"," if" This is my script:

function onTouch(part) local human = part.Parent:findFirstChild("Humanoid") if game.teams.Hostile = true then(human == nil) then return end human.Health = 0 end script.Parent.Touched:connect(onTouch)

2 answers

function onTouch(part)
local human=part.Parent:findFirstChild("Humanoid")if
game.teams.Hostile==true and human ~=nil then 
human:Destroy()
end

script.Parent.Touched:connect(onTouch)

get rid of the then and the == sign always goes between the if and the then example:if 1+1==2then

and you can also use human==nil instead of human :Destroy() works both ways

this script is basically saying if the team is hostile and the human is there then kill the human when the part is touched

2 comments

0

there is issue with line 7 about end <'eof'>

0

oh yeah add an extra end to for the function onTouch

Hey Pal, this should work!

function onTouched(part)
local h = part.Parent:findFirstChild("Humanoid")
if h~= nil then
wait (0.001)
h.Health = 0 end end

script.Parent.Touched:connect(onTouched)

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