my drone is freaking out
local tweenservice = game:GetService("TweenService")
local info = TweenInfo.new(0.5)
local function REAL(g)
return g%360
end
local movements = {
["W"] = 90,
["A"] = 180,
["S"] = 270,
["D"] = 360
}
script.Parent.Name = script.Parent.owner.Value.." Drone"
local local_script = script.Parent.LocalScript:Clone()
local_script.Enabled = true
local_script.Parent = game.Players:FindFirstChild(script.Parent.owner.Value).Character
local goal = Vector3.new(script.Parent.PrimaryPart.CFrame*Vector3.new(0,0,1))
script.Parent.movement.OnServerEvent:Connect(function(plr,data)
if plr.Name ~= script.Parent.owner.Value then
return
end
local res = 0
local loops = 0
for i,v in pairs(data) do
if v== "E" or v== "Q" then continue end
loops +=1
res += movements[v]
end
if loops>= 1 then
res= REAL(res)/loops
end
print(data)
print(res)
local goal = Vector3.new(math.cos(res),math.sin(res),script.Parent.PrimaryPart.Position.Y)
local x,y,z = CFrame.lookAt(script.Parent.PrimaryPart.Position,script.Parent.PrimaryPart.Position+goal):ToOrientation()
local ori = Vector3.new(math.deg(x),math.deg(y),math.deg(z))
tweenservice:Create(script.Parent.PrimaryPart,info,{Orientation =ori}):Play()
end)