How can I get the players mouse position and fire objects out of it?

Hello, I want to make a morph for myself in a game im making, where I can fire out objects, but Im not sure how to get the players mouse position and how to do this.

1 Like

You can use: local mouse= PlayerGetMouse()
I think it only works on local scripts.
Position = mouse.Position
If you want the part that the mouse is pointing at you can use mouse.Hit
I think this works, if not message me.

1 Like

I have this so far

local Orb = game:GetService("ReplicatedStorage"):WaitForChild("Objects"):WaitForChild("Orb")

local Mouse = game.Players.LocalPlayer:GetMouse()

Mouse.Button1Down:Connect(function()
	local Position = Mouse.Hit
	
	local orbClone = Orb:Clone()
	orbClone.Parent = workspace
	
	orbClone.Position = script.Parent.HumanoidRootPart.Position + Vector3.new(2, 0, 2)
	
	local orbBoost = Instance.new("LinearVelocity")
	orbBoost.Parent = orbClone
	orbBoost.MaxForce = 100000000
	orbBoost.VectorVelocity
end)

I’m not sure what to do next, I never calculated something like this. So I’m not sure what I should set the velocity at.

You need to use RemoteEvents otherwise other players will not see what is being cloned. Things done in LocalScripts do not replicate to the server

You can do something like:


local Mouse = game.Players.LocalPlayer:GetMouse()

Mouse.Button1Down:Connect(function()
	local Position = Mouse.Hit

       remoteevent:FireServer(pos)
	
end)

in script (server):

local Orb = game:GetService("ReplicatedStorage"):WaitForChild("Objects"):WaitForChild("Orb")
remoteevent:OnServerEvent:Connect(function(player,pos))

	local orbClone = Orb:Clone()
	orbClone.Parent = workspace
	
	orbClone.Position = player.Character:GetPivot() + Vector3.new(2, 0, 2)
	
	local orbBoost = Instance.new("LinearVelocity")
	orbBoost.Parent = orbClone
	orbBoost.MaxForce = 100000000
	orbBoost.VectorVelocity

end)
1 Like

Off-topic but add a debounce to prevent exploiters from spam-adding the parts to server that would otherwise crash the server.

2 Likes

Are you saying i’m offtopic or you? Because neither of us are offtopic

Also yes, add debounce

1 Like