For some reason this script will not work with the while command attached.
while _G.gTime == true do i = workspace.Bullet:GetChildren() --Change "ModelNameHere" to the name of the model you want to anchor. Note that it can't be a name with spaces in it or the script won't work. for h = 1, #i do if i[h].className == "Part" then i[h].Anchored = true end end wait(0.05) end
Thank you.
The code is syntactically correct but there are a few problems that could be causing the logic error. First and foremost, I do not recommend using the ClassName
API. Use the IsA
method instead. More specifically, the condition in the if
statement should be replaced with i[h]:IsA("BasePart")
.
What's the difference between Part
and BasePart
? The answer is simple; Part
is only one type of BasePart
. There are many types of BasePart
s including WedgePart
, MeshPart
, and TrussPart
. Your if
statement was only checking for the regular Part
. In particular, these aforementioned classes are all subclasses of BasePart
. As an analogy, imagine you have many pizzas with different toppings.. You have pepperoni pizzas, cheese pizzas, vegetable pizzas all of which are very different pizzas. However all of these pizzas can be grouped under the more general term, Pizza
.
Just a few more small errors (doesn't change the logic in anyway) that I feel deserve to be pointed out. First, you shouldn't use single variable names (unless it's a generally accepted convention, for example the letters i
, j
, and k
in loops, or the letters x
and y
for coordinates). In your code you use the variable names h
and i
which aren't very descriptive. Change i
to Bullets
. The h
variable seems like a fairly arbitrary letter. Instead, you should use i
instead as it inherently makes its meaning more clear to others. Second, the use of _G
is usually frowned down upon because it unnecessarily makes values unsafe and usually hints towards code smell. Try restructuring your design as to avoid the use of _G
.
Good luck!