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

This function prints a certain text regardless of the if statement I put, help?

Asked by 5 years ago

So it is supposed to only print "That brick got rekt" if the brick is deleted, but when I took away the line that calls the Partwreck() function, it still printed "That brick got rekt" instead of "Why dat brick still alive??" Anyone know why? Also the script is in workspace, and it is named "Script1"

function Partwreck()
    local Tester = workspace.Tester
    wait(3)
    workspace.Tester:Destroy()
end

Partwreck()

wait(1)

function Destro()
    local Script1 = workspace.Script1
    if Tester == nil then
        print("That brick got rekt")
    if Tester ~= nil then
        print("Why dat brick still alive??")
    end
    end
end

Destro()

1 answer

Log in to vote
0
Answered by 5 years ago

Use else if for the second if, and call the local variables outside of the functions.

local Tester = workspace.Tester --Local Variables called outside of functions.
local Script1 = workspace.Script1

function Partwreck()
    wait(3)
    workspace.Tester:Destroy()
end

Partwreck()

wait(1)

function Destro()
    if Tester == nil then
        print("That brick got rekt")
    elseif Tester ~= nil then -- Use elseif instead of if
        print("Why dat brick still alive??")
    end
end

Destro()
0
This still won't; work?~~ local Tester = workspace.Tester local Script1 = workspace.Script1 function Destroyer() wait(2) workspace.Tester:Destroy() end function Talker() if Tester == nil then print("That Brick is Dead Boi") elseif Tester ~= nil then print("Why is this brick still here?") end end Destroyer() wait(1) Talker()~~ hawkeye1940 8 — 5y
0
Swap == and ~=, seems to detect them backwards. BlauKitten 88 — 5y
Ad

Answer this question