Object not tweening to mouse properly

I’m addind a special ability in my game where it can create a ball that one shots whoever it touches, and it tweens to the mouse, but whenever I test it, Instead of tweening to the mouse, it tweens to 0,0,0

LocalScript

local uis = game:GetService("UserInputService")
local plr = game.Players.LocalPlayer
local m = plr:GetMouse()
local mouse = m.Hit

uis.InputBegan:Connect(function(inp)
	if inp.KeyCode == Enum.KeyCode.Q then
		script.Parent.AbilityEvent:FireServer(mouse)
	end
end)

ServerScript

local cooldown = 15
local useTime = 5
local active = false
local oncd = false
local equipped = false

script.Parent.AbilityEvent.OnServerEvent:Connect(function(plr, mouse)
	if equipped == true then
	if active == false and oncd == false then
		active = true
		local char = plr.Character
		local hrp = char:WaitForChild("HumanoidRootPart")
		local cf = hrp.CFrame
		local lv = cf.LookVector
		local part = Instance.new("Part")
		part.CFrame = cf + (lv * Vector3.new(5,5,5))
		part.Anchored = true
		part.BrickColor = BrickColor.new("Hot pink")
		part.Material = "Neon"
		part.Shape = "Ball"
		part.Size = Vector3.new(4,4,4)
		part.CanCollide = false
		part.Parent = workspace
		part.Touched:Connect(function(hit)
			if hit.Parent:FindFirstChild("Humanoid") then
				hit.Parent.Humanoid.Health = 0
			end
		end)
		local ts = game:GetService("TweenService")
		local tweenInfo = TweenInfo.new(useTime, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0)
		local goal = {Position = Vector3.new(mouse)}
		local tween = ts:Create(part,tweenInfo,goal)
		
		tween:Play()
		
		wait(useTime)
		part:Destroy()
		active = false
		oncd = true
		wait(cooldown)
		oncd = false
	end
	end
end)

script.Parent.Equipped:Connect(function()
	equipped = true
end)

script.Parent.Unequipped:Connect(function()
	equipped = false
end)
1 Like

m.Hit is already a Vector3, so putting it inside of Vector3.new() turns it into 0, 0, 0. Try removing the Vector3.new() part from your goal variable to fix the issue:

local goal = {Position = mouse}

I tried this and it returned the error

  01:46:01.186  TweenService:Create property named 'Position' cannot be tweened due to type mismatch (property is a 'Vector3', but given type is 'CoordinateFrame')  -  Server - AbilityServer:32

Oh yeah, my bad :sweat_smile:. m.Hit returns a CFrame, so just change the variable mouse from your LocalScript to equal m.Hit.Position to fix the issue.

When I attempted this, the part just outright spawned in the void (3037.944, -4139.57, -7083.656)

Hi! Maybe that’s because you pointed the mouse into the sky. Try printing the m.hit.position just to make sure.

If that’s the case, what you can to is set a distance limit for the ability like this (or something like that)

If (player.Character.HumanoidRootPart.Position + m.hit.position).Magnitude > MaxDistance then

Target = player.Character.HumanoidRootPart.CFrame:PointToObjectSpaceP(m.hit.Position) * MaxDistance

End

(Thanks for the help @Luke_gamer226)

Not sure if this is right (i’m not a pro scripter) but basically you’ll need to get the normalized direction from the player and the m.hit and multiply it for the distance you want

1 Like

Use ‘’’ for make a script window, and end it with ‘’’

1 Like

I didn’t point the mouse into the sky tho, so there shouldnt be a reason for it to spawn in the void.

Can you print mouse in both the local and server script? Do they print the same thing?

I was testing this, so I moved the mouse variable around and fixed it