How do I make a Turret that follows the player's mouse (X and Z wise, no Y) with/without welds? I've tried multiple methods but not all of them work right.
This should help you out. You'll have to modify a few things and suit it to whatever you're doing. Also, keep in mind that this isn't a request site, it's a help site, so refrain from asking for such things in the future.
[LocalScript]
local part = workspace.Part -- change this to the part local camera = workspace.CurrentCamera game:GetService("UserInputService").InputChanged:connect(function(inputObject) if (inputObject.UserInputType ~= Enum.UserInputType.MouseMovement) then return end local mousePosition = inputObject.Position local turretPosition = part.CFrame.p local mouseRayUnit = camera:ScreenPointToRay(mousePosition.X, mousePosition.Y) local mouseRay = Ray.new(mouseRayUnit.Origin, mouseRayUnit.Direction * 1000) local _, mouseTarget, _ = workspace:FindPartOnRay(mouseRay) part.CFrame = CFrame.new(turretPosition, mouseTarget) end)
Problem is that a model cant have a cframe
That script work, All you have to do is edit the part for example
local part = workspace.["Zombie"].Barrel -- change this to the part local camera = workspace.CurrentCamera game:GetService("UserInputService").InputChanged:connect(function(inputObject) if (inputObject.UserInputType ~= Enum.UserInputType.MouseMovement) then return end local mousePosition = inputObject.Position local turretPosition = part.CFrame.p local mouseRayUnit = camera:ScreenPointToRay(mousePosition.X, mousePosition.Y) local mouseRay = Ray.new(mouseRayUnit.Origin, mouseRayUnit.Direction * 1000) local _, mouseTarget, _ = workspace:FindPartOnRay(mouseRay) part.CFrame = CFrame.new(turretPosition, mouseTarget) end)
The [""] is if its a model