I’m making a pathfinding script, and I’m trying to create a goal part if a tile matches a position, but when I add the line to try and duplicate the part, it breaks the script.
Here’s the script:
for i, tile in pairs(tiles:GetChildren()) do
local primaryPart = playerPokemon.PrimaryPart
if tile.Position == primaryPart.Position + distanceTable[key] and tile:GetAttribute("occupiedBy") ~= "pokemon" then
tween(primaryPart, {CFrame = tile.CFrame * CFrame.Angles(0, math.rad(rotationTable[key]), 0)}, 0.25, nil, nil, true, function()
for i, tileLookAt in pairs(tiles:GetChildren()) do
if tileLookAt.Position == primaryPart.Position + distanceTable[key] then
playerPokemon:PivotTo(CFrame.lookAt(primaryPart.Position, tileLookAt.CFrame.Position))
end
end
end)
primaryPart.CFrame = CFrame.lookAt(primaryPart.Position, tile.CFrame.Position)
primaryPart:GetPropertyChangedSignal("Position"):Connect(function()
camera.CFrame = CFrame.new(playerPokemon.PrimaryPart.Position + Vector3.new(0, 20, 10), playerPokemon.PrimaryPart.Position)
end)
--[[createObject("Part", {
Name = "Goal",
Size = tile.Size,
Position = tile.Position,
Parent = workspace,
CanCollide = false,
Transparency = 1,
createObject("IntValue", {
Name = "G"
})
})]]
if tile:GetAttribute("occupied") and tile:GetAttribute("occupiedBy") ~= "pokemon" then
playerData.AddItemToBag(tile:GetAttribute("occupiedBy"), tile:GetAttribute("itemAmount"))
pickUpItem(playerData.PlayerName, tile:GetAttribute("itemAmount"), tile:GetAttribute("occupiedBy"))
utilities.PlaySound(require(assetsFolder:WaitForChild("Audio")).PickUpItem)
tile:SetAttribute("itemAmount", nil)
tile:WaitForChild(tile:GetAttribute("occupiedBy")):Remove()
tile:SetAttribute("occupiedBy", "pokemon")
end
elseif tile.Position == primaryPart.Position + distanceTable[key] and tile:GetAttribute("occupied") and tile:GetAttribute("occupiedBy") == "pokemon" then
utilities.PlaySound(require(assetsFolder:WaitForChild("Audio")).Boing)
end
It’s currently commented, but here’s the culprit:
--[[createObject("Part", {
Name = "Goal",
Size = tile.Size,
Position = tile.Position,
Parent = workspace,
CanCollide = false,
Transparency = 1,
createObject("IntValue", {
Name = "G"
})
})]]
Any help will be appreciated, thanks!