I didn't want to have to make an entire post on this site to get help (because I'm pretty sure my error is just a stupid mistake that I'm overlooking), so I tried asking this question in the scripting helpers DISCORD, but I've come to the conclusion that the scripting helpers discord server is pretty much useless when it comes to actually getting help because pretty much everytime I've tried to ask a question, even a relatively simple one, I get completely ignored (despite both staff and other members being online). So here I am.
Here's my function:
function initiateBattle() wait(1) local arena = game.ReplicatedFirst.arena:Clone() arena.Parent = game.Workspace wait(1) local battleData = initiate:FindFirstChild("battleData") local enemies = battleData:GetChildren() for index, enemy in pairs(enemies) do local enemyData = game.ReplicatedFirst.enemies:FindFirstChild(enemy.Value):Clone() local enemyNum = enemy.Name local enemyModel = game.ReplicatedFirst.enemies:FindFirstChild(enemy.Value.."Model"):Clone() enemyData.Parent = script.Parent.battle.enemies enemyModel.PrimaryPart = enemyModel["Left Leg"] enemyModel.Parent = game.Workspace enemyModel:MoveTo(Vector3.new(arena:FindFirstChild(enemyNum).Position)) end end
(This is a turn-based RPG style game for clarification)
--HOW THE FUNCTION WORKS So, when the function is fired, it clones a model "arena" from ReplicatedFirst and places it in workspace. Then via the "for" loop it finds how many enemies are being battled and what kind each of them are. This is just a test battle so only one enemy is being fought. It grabs both the enemies battleData and the enemies battleModel from ReplicatedFirst and places them in workspace. The battleData gets successfully cloned to its respective spot, and the battleModel gets successfully cloned into workspace. The problem is, however, that the enemyModel is supposed to be cloned to workspace and then moved to its proper spot in the arena, which is where the problem arises. The script reads the enemies name successfully with "enemyNum" (the enemies name = enemy1), and is supposed to find "enemy1" in arena (which exists inside of arena as a part) and then move the enemies model to the "enemy1" position inside of "arena". There are no errors in this part, no spelling mistakes or anything. The enemies name successfully registers as "enemy1" and the game successfully finds "enemy1" in arena, however fails to move the enemy to its position.
--THE ACTUAL PROBLEM I've narrowed down the problem to the line "enemyModel:MoveTo(Vector3.new(arena:FindFirstChild(enemyNum).Position))" because if i replace the "arena:FindFirstChild(enemyNum).Position" with a coordinate value, such as (10,10,10), the enemy successfully moves to (10,10,10). However, as the line currently stands with it trying to find "enemy1" in "arena", the enemy just gets cloned into workspace and is moved to point (0,0,0). Also, no errors appear in console.
Tbh it's probably a really simple and stupid mistake that I've just been overlooking, but I for the life of me just can't seem to spot it.
All help is appreciated!
The problem is that you're essentially wrapping a Vector inside of a Vector.
The line should be changed to:
local enemySpawn = arena:FindFirstChild(enemyNum) if enemySpawn then --Indexing the 'Position' Property already returns a Vector enemyModel:MoveTo(enemySpawn.Position) else print("No spawn found") end