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

Why does this script sometimes not remove the models?

Sorry for the vague question title.

Here is my script.. it works most of the time, but sometimes it will give an error saying that "lavawalk2 isn't a valid member of Workspace," and sometimes it won't remove the models, just recreate over them.

I'm not sure why, as far as my scripting goes, nothing looks wrong.

math.randomseed(tick())

while true do
	
print("now cloning in obbies")
print(" ")

	
num = math.random(2)

if num == 1 then
	game.Lighting.lavajump:Clone().Parent = workspace elseif
	num == 2 then
	game.Lighting.lavawalk:Clone().Parent = workspace
end

num2 = math.random(2)

if num2 == 1 then
	game.Lighting.lavajump2:Clone().Parent = workspace elseif
	num == 2 then
	game.Lighting.lavawalk2:Clone().Parent = workspace
end

print("the first obby is".." "..num)
print("the second obby is".." "..num2)

wait(4)

print("now removing obbies")
print(" ")

wait(1)

if num == 1 then
	game.Workspace.lavajump:Remove() elseif
	num == 2 then
	game.Workspace.lavawalk:Remove()
end

if num2 == 1 then
	game.Workspace.lavajump2:Remove() elseif
	num2 == 2 then
	game.Workspace.lavawalk2:Remove()
	
wait(2)

end


end

3 comments

0

which line did the error start to occur? (it should be stated in the output)

0

Try using game.Workspace:WaitForChild("lavawalk2"):Remove() The script is probably running before the lavawalk2 had been created in Workspace

0

^ Almost certainly.

1 answer

Alright where you put your if statementsand then after that you out lavajump use the :findFirstChild() method or :WaitForChild. Something like this:

game.Lighting.:findFirstChild("lavaJump") :clone().Parent = workspace
game.Lighting.:WaitForChild("lavaJump") :clone().Parent = workspace

Try the one above for every code that you search for lavaJump or anything else and then tell me if it works or not.

I hope I helped and thank you for reading this answer!

~~ KingLoneCat

2 comments

0

I tried this and the error does not show up anymore, but the problem persists. What appears to be happening is that whenever one of the obbies that is already cloned in is being removed and then recreated, it'll just stay there. Odd.

0

That's because later you put it to removing those obbies if the number is equal to 1 or 2

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