Hello, I’m trying to make a gun that points to where your mouse is but my script is not working. Can someone help me?
local seat = script.Parent.Seat
local mesh = script.Parent.MeshPart
seat.Touched:Connect(function(touch)
local h = touch.Parent:FindFirstChild("Humanoid")
if h then
wait(1)
if seat.Occupant ~= nil then
local seated = true
print("Player is seated")
local player = game.Players:GetPlayerFromCharacter(h.Parent)
print(player.Name)
local mouse = player:GetMouse()
print("Got the mouse")
while wait(0.1) do
mesh.CFrame = CFrame.new(mesh.Position, mouse.CFrame)
end
end
end
end)
If this is a server-sided script, it wouldn’t work. You can only get the mouse in a localscript as the mouse isn’t replicated to the server. I would fire a remove event to check the mouse’s position.
Mouse.Position doesn’t exist as a property. I’m assuming you’re referring to its X and Y properties but those are in screen space which is not want OP wants.
the best option would be to use 2 scripts in my game I had it like this
create a script and that the seat is the parent from the same script you create a local script and when the player sits down copies the local script to his character to later activate it the control part must be in the local script and also from the script normal when the player jumps you have to delete the local script