(Following tutorial from here)
@McDmnks if you can help debug it would be appreciated
I’m getting the error in the title, in the UnitMove script in ServerScriptService. I’m not sure why this is happening. If anyone can help me fix the error it will be appreciated!
Explorer:
UnitMove: (firing event at line 8)
local positions = {}
game.ReplicatedStorage.Remotes.MoveUnit.OnServerEvent:Connect(function(player, hitpos, unit)
local loop = true
positions[unit] = (hitpos)
game.ReplicatedStorage.Remotes.CreateBeam:FireClient(player, positions[unit][1], unit, false)
while loop and unit.Parent and positions[unit][1] == hitpos do
unit.PrimaryPart.Vel.PlaneVelocity = Vector2.new(hitpos.X - unit.PrimaryPart.Position.X, hitpos.Z - unit.PrimaryPart.Position.Z).Unit * unit:GetAttribute("Speed")
if (unit.PrimaryPart.Position - positions[unit][1]).Magnitude > 1 and unit.Parent and positions[unit][1] == hitpos then
unit:SetAttribute("repeating", true)
else
loop = false
unit:SetAttribute("repeating", false)
end
task.wait(0.1)
end
if unit.Parent then
if unit:GetAttribute("repeating") == false then
unit.PrimaryPart.Vel.PlaneVelocity = Vector2.new(0, 0)
game.ReplicatedStorage.Remotes.CreateBeam:FireClient(player, positions[unit][1], unit, true)
end
end
end)
UnitMoveHelper:
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
mouse.Button1Down:Connect(function()
for i,v in pairs(game.Workspace.Units:GetChildren()) do
if v:GetAttribute("Selected") == true then
local hit = Vector3.new(mouse.Hit.Position.X, mouse.Hit.Position.Y, mouse.Hit.Position.Z)
game.ReplicatedStorage.Remotes.MoveUnit:FireServer(hit, v)
end
end
end)