#help with moving models bug
1 messages · Page 1 of 1 (latest)
script
OK
I FOUND THE PROBLEM
@light kiln
so models, moving there individual parts messes some things up.
you would want to use a method called ":PivotTo()" which is used by all baseparts and instances that can be moved
the parameter uses a cframe
since models take a good chunk of your game, you could use pivotTo on your parts
replace this:
if newCard:IsA("Model") then
print("card is model")
newCard:MoveTo(cardSpawn.Position)
for _, part in pairs(newCard:GetChildren()) do
part.Anchored = true
end
else
print("card is part")
newCard.Position = cardSpawn.Position
newCard.Orientation = cardSpawn.Orientation
newCard.Anchored = true
end
with this:
newCard:PivotTo(cardSpawn.CFrame)
local newCardChild = newCard:GetChildren()
if #newCardChild > 0 then
for _, part in pairs(newCardChild) do
part.Anchored = true
end
else
newCard.Anchored = true
end
Also I noticed another error in this line:
newCard:MoveTo(cardSpawn.Position)
:MoveTo() is a method exclusively for humanoids. MoveTo() will make a humanoid walk to position or part however, your part isn't a character and it doesn't have a humanoid so :MoveTo() becomes invalid
I'll explain what I did.
so first :PivotTo() is an action that changes a basepart's or model's cframe.
A cfame is a data type that takes the position AND the orientation and combines it into one!
So i set the cframe of the object to the spawnCFame.
I got the children of the newCard and stored it into a variable. After I check if the number of children of the newCard is greater than 0 meaning that it actually has children.
If it's not then we don't loop through it and we just anchor the card itself
also you can get rid of the excessiveness of the randomCard. You have it set to the scope of the first if statement but you can move it outside of it.
@light kiln ALL DONE
COME TAKE A LOOK
tysm but i didnt respond cause you answered me at 3:41 am in my country
im going to change the code, thanks!
ye i got confused i recently learned move to and switch up pivot and move to
frequently
it works! ty
also it gives me this error when it spawns a part instead of a model:
oh sorry the part also has a click detector, script and texture so i cant really do the child thing
IGNORE THIS I FIXED IT
** You are now Level 4! **