Hello,
I am working on a turret where you sit and it turns to where your mouse is pointed, but I have a problem.
It doesn’t do anything.
I have it so a localscript gets cloned to the playergui when a player sits so it then via a RemoteEvent fires when the mouse moves and it has Mouse.Hit.Position as it’s parameter. Which is then hooked up on a server script that sets the primary part’s cframe.
Local Script:
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Obj = script.Obj
local Mouse = Player:GetMouse()
Mouse.Move:Connect(function()
Obj.Value.Seat.Handler.RemoteEvent:FireServer(Mouse.Hit.Position)
end)
Server Script:
local Players = game:GetService("Players")
local Seat = script.Parent
local Active = false
local NewScript = nil
script.RemoteEvent.OnServerEvent:Connect(function(Player, MouseP)
script.Parent.Parent.Guns.Gun:SetPrimaryPartCFrame(CFrame.new(script.Parent.Parent.Guns.Gun.PrimaryPart.CFrame.Position, MouseP))
script.Parent.Parent.Guns.Gun2:SetPrimaryPartCFrame(CFrame.new(script.Parent.Parent.Guns.Gun2.PrimaryPart.CFrame.Position, MouseP))
end)
Seat.ChildAdded:Connect(function(x)
if not Active then
if x.Name == "SeatWeld" then
Active = true
local Player = Players:GetPlayerFromCharacter(x.Part1.Parent)
if Player then
if Player.PlayerGui then
NewScript = script.LocalScript:Clone()
NewScript.Parent = Player.PlayerGui
NewScript.Obj.Value = Seat.Parent
NewScript.Disabled = false
end
end
end
end
end)
Seat.ChildRemoved:Connect(function(x)
if x.Name == "SeatWeld" then
if Active then
Active = false
pcall(function() NewScript:Destroy() end)
NewScript = nil
end
end
end)
What’s the issue?