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

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

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

✓ Accepted answer

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()

2 comments

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()~~

0

Swap == and ~=, seems to detect them backwards.

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