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

If statement won't work, but no error in the output?

I am trying to make a script so that when the value (parent of the Script), is true, a block of code fires. For some reason, when the value is true (I checked this by the way), the code does not fire. Also, the script is not in server storage, or any other place where a script won't run.

Here is my code:

if script.Parent.Value == true then
	print("Success")
	script.Parent.Parent.Parent = workspace
	script.Parent.Parent.Position = Vector3.new(-70.844, 45.947, -233.831)
	script.Parent.Parent.Position = Vector3.new(-0.28, 0.01, -2.68)
	workspace.tele1.Position = Vector3.new(-75.923, 37.99, -223.249)
	workspace.tele2.Position = Vector3.new(1368, -74.568, -53.679)
end

4 comments

0

By the way, the script, its parent (which is an object) and its parent (a folder) are parented to Workspace.

0

Can you explain what the script is supposed to do?

0

Its supposed to position a union a certain way.

0

Your if-statement is evaluated upon runtime, it's not going to yield for you. If you want to run a block of code when the condition is met, you must wrap it in a callback passed to Instance:GetPropertyChangedSignal("Value"):Connect(Callback)

2 answers

you can try

repeat
	wait()
until
script.Parent.Value == true
print("Success")
script.Parent.Parent.Parent = workspace
script.Parent.Parent.Position = Vector3.new(-70.844, 45.947, -233.831)
script.Parent.Parent.Position = Vector3.new(-0.28, 0.01, -2.68)
workspace.tele1.Position = Vector3.new(-75.923, 37.99, -223.249)
workspace.tele2.Position = Vector3.new(1368, -74.568, -53.679)

[REMEMBER TO MARK ME AS THE CORRECT ANSWER IF I HELPED TO FIX YOUR CODE, THANKS!]

-- Explanation --

Your if-statement will fire when the game runs. But not forever, it only fire once when game starts.

So if you want to fix this, a little lazy answer is loop the if-statement and fire it every 1 second.

while wait(1) do
    -- Your entire code
end

Note: The code will work, but it's not the best answer. You can try to research for more answer. Thanks for reading, and I hope this helped too! Best of the luck, bye!

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