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

Instance.new wont anchor?

while true do
	Instance.new("Part", game.Workspace).Name = "Fred"
	game.Workspace.Fred.Anchored = true
	game.Workspace.Fred.CanCollide = false
	wait(1)
end

--> Whenever the part is inserted, it will not anchor, but that is only on a "while true do" loop, when I remove the loop, it anchors just fine, but it only makes one?

2 answers

✓ Accepted answer

Because you're making a new part in the Workspace with the same name each time, the game will not know what part you are referencing.

This should fix the problem:

a = 1/0 -- Variable equal to infinity
for i = 1,a do -- A for loop that will go on forever, like the while
	part = Instance.new("Part",game.Workspace)
	part.Name = ("Part"..i)
	part.Anchored = true
	part.CanCollide = false
	wait(1)
end

1 comment

0

I didn't downvote btw

That's because you used it's name. The script will find the name, then anchor the part.

Then hen the loop repeats, it'll find the name, the old one, and even though there are 2 of them, it will anchor the one it finds, the first one

while wait(1) do
   local part =  Instance.new("Part", game.Workspace)
part.Name = "Fred"
    part.Anchored = true
    part.CanCollide = false
end

You can use the Instance.new as a var, and that's how you would mess with it.

1 comment

0

This is essentially the same as mine, but this one looks cleaner and his explanation is better. I suggest using this to comprehend instead.

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