How to get the Mouse Position in the Server

I tried searching on devforum to fix this but there answers didnt work. I have a value in a folder in the player that has the mouse position, but when I use it in the script it doesnt go toward the mouse. Any help?

Server:

game.Players.PlayerAdded:Connect(function(plr)
	game.ReplicatedStorage.Remotes.MousepOSITION.OnServerEvent:Connect(function(mousep)
	local tweenservice = game:GetService('TweenService')
	local mouse = mousep:GetMouse()
	local clone = game.ReplicatedStorage.IceCube:Clone()
	local char = plr.Character
	clone.CFrame = char.LowerTorso.CFrame
	clone.Position = Vector3.new(clone.Position.X, 100, clone.Position.Z)
	clone.Parent = char
	local tweeninfo = TweenInfo.new(
		1,	
		Enum.EasingStyle.Linear,
		Enum.EasingDirection.Out,
		0,
		false,
		0
	)
	local tween = tweenservice:Create(clone, tweeninfo, {Position = mousep.stats.MousePosition.Value})
	tween:Play()
	tween.Completed:Wait()
	local hitboxclone = game.ReplicatedStorage.HitBox:Clone()
	hitboxclone.Parent = clone
	hitboxclone.Position =  clone.Position
	local explosion = Instance.new('Explosion')
	explosion.Parent = clone
	explosion.BlastRadius = '10'
	local smoke = game.ReplicatedStorage.Ice:Clone()
	smoke.Parent = clone
		clone:Destroy()
	end)
end)

Client (in tool):

local UIS = game:GetService("UserInputService")
local tweenservice = game:GetService('TweenService')
UIS.InputBegan:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.E then 
		local plr = game.Players.LocalPlayer
		local mouse = plr:GetMouse()
		local mousep = mouse.Hit
		game.ReplicatedStorage.Remotes.MousepOSITION:FireServer(mousep)
		plr.stats.MousePosition.Value = mousep.Position
			
	end
end)

Try Mouse.Hit.Position instead of Mouse.Hit

It didnt work, something strange is it came out as a player instance

I also got this error:
image

I think this is your issue, you would already be passing the mouse’s position through the remote event, so you can just put Position = mousep

You provided the position here but forgot that the player will always be the first parameter…

game.ReplicatedStorage.Remotes.MousepOSITION.OnServerEvent:Connect(function(player, mousep)

Remove the playerAdded and don’t try to get the mouse.

game.ReplicatedStorage.Remotes.MousepOSITION.OnServerEvent:Connect(function(player, mousep)
	local tweenservice = game:GetService('TweenService')
	local clone = game.ReplicatedStorage.IceCube:Clone()
	local char = plr.Character
	clone.CFrame = char.LowerTorso.CFrame
	clone.Position = Vector3.new(clone.Position.X, 100, clone.Position.Z)
	clone.Parent = char
	local tweeninfo = TweenInfo.new(
		1,	
		Enum.EasingStyle.Linear,
		Enum.EasingDirection.Out,
		0,
		false,
		0
	)
	local tween = tweenservice:Create(clone, tweeninfo, {Position = mousep.Position})
	tween:Play()
	tween.Completed:Wait()
	local hitboxclone = game.ReplicatedStorage.HitBox:Clone()
	hitboxclone.Parent = clone
	hitboxclone.Position =  clone.Position
	local explosion = Instance.new('Explosion')
	explosion.Parent = clone
	explosion.BlastRadius = '10'
	local smoke = game.ReplicatedStorage.Ice:Clone()
	smoke.Parent = clone
		clone:Destroy()
	end)
end)
1 Like

And look at that, it works like a charm! Thanks for the help!