Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

"Workspace.Tool.Script:15: 'end' expected (to close 'function' at line 12) near 'else'"?

Asked by 8 years ago

I'm trying to make a tool that burns whatever bricks you click on. Currently returns " Workspace.Tool.Script:15: 'end' expected (to close 'function' at line 12) near 'else'"

function Burn(part)
    print "burning part"
    fire = Instance.new("Fire")
    fire.parent = part 
    for burning=0,1, 0.1 do
        wait(1)
        part.Transparency = burning
    end
    part:Destroy()
end

function Button1Down(mouse)
    setfireto = mouse.Target
    if setfireto ==  nil then return end
    else Burn(setfireto)
    end
end

0
The second problem in your code is that 'parent' on Line 4 is not capitalized - I think that fixes the problem. TheDeadlyPanther 2460 — 8y

3 answers

Log in to vote
0
Answered by 8 years ago

The problem is at line 14. "else" only works inside of if statements. So, Instead of:

 if setfireto ==  nil then return end
    else Burn(setfireto)

do:

if not setfireto then
return
else
Burn(setfireto)
end

Also, in case you're wondering, you don't have to check if a value is nil by doing var == nil, you can just do not var

So, instead of:

L = 0
print(L == nil)
--Output: false

you can simplify it by adding "not" before the variable like this:

L = 0
print(not L)
--Output: false
0
The error stopped, but the tool still does nothing. Any idea why? cheetosrevenge 20 — 8y
0
line 4, the P in parent should be capitalized User#14829 0 — 8y
Ad
Log in to vote
0
Answered by 8 years ago

You need to capitalize the P in: Fire.parent

Make it like:

Fire.Parent

Good luck ;)

Log in to vote
0
Answered by 8 years ago

if its a function error where end expected at line 12 cuz you need a end on line 18 :/

Answer this question