Hello, I have a couple scripts which rotate a turret, but for some reason it stopped working and I have no idea why.
LocalScript:
wait(0.3)
local model = game.Workspace.AmericanBase.Cannons["Anti-Air1"]
local SG = script.Parent.UI
local value = SG.BulletsLeft
local label = SG.TextLabel
local mesh = model.MeshPart
local seat = model.Seat
local player = game.Players.LocalPlayer
local event = model.Rotate
local value = model.Touching
-----------------------------------------------------------------------------
print(player.Name)
local mouse = player:GetMouse()
print("Got the mouse")
while wait(0.001) do
if seat.Occupant ~= nil then
mouse.Icon = "rbxassetid://5030106330"
local pos = mouse.Hit.Position
if value.Value == true then
event:FireServer(pos)
end
else
mouse.Icon = ""
end
end
ServerScript:
local event = script.Parent.Rotate
local mesh = script.Parent.MeshPart
event.OnServerEvent:Connect(function(plr, pos)
mesh.CFrame = CFrame.new(mesh.Position, pos)
end)
That’s not how you use the method you have to find the right and up vectors and supply them to the function.
local Direction = (pos - mesh.Position).Unit --assuming you want it to face pos
local RightVector = Direction:Cross(Vector3.FromNormalId(Enum.NormalId.Top))
local UpVector = RightVector:Cross(Direction)
mesh.CFrame = CFrame.new(mesh.Position, RightVector, UpVector)
local event = script.Parent.Rotate
local mesh = script.Parent.MeshPart
event.OnServerEvent:Connect(function(plr, pos)
local Direction = (pos - mesh.Position).Unit
local RightVector = Direction:Cross(Vector3.FromNormalId(Enum.NormalId.Top))
local UpVector = RightVector:Cross(Direction)
mesh.CFrame = CFrame.new(mesh.Position, RightVector, UpVector)
end)