Help Needed with Snowball Script - Not Throwing Properly

Hey everyone,

I hope you’re doing well. I’ve been working on a snowball script for my Roblox game, and I’ve run into a bit of a snag. While I’ve managed to resolve an earlier error, I’m now facing an issue where the snowball isn’t being thrown at the mouse position as intended. Instead, it simply appears at the mouse pointer.

Here’s a snippet of my current script:

local snowBall = script.Parent
local direction

script.Parent.PickenTarget.OnServerEvent:Connect(function(player, mouse)
	direction = mouse
	print(direction)

	local function throw()
		local Handle = snowBall.Handle
		local newSnowBall = Handle:Clone()
		newSnowBall.Parent = workspace
		newSnowBall.CanTouch = false
		newSnowBall.CanCollide = true
		newSnowBall.Position = direction + direction.Unit * 3

		local throwSpeed = 100
		local throwDirection = (direction - newSnowBall.Position).unit
		newSnowBall.AssemblyLinearVelocity = throwDirection * throwSpeed

		print(direction)
	end

	snowBall.Activated:Connect(throw)
end)

Localscript:

local player =game.Players.LocalPlayer
local mouse = player:GetMouse()

script.Parent.Activatced:Connect(function()
	script.Parent.PikenTarget:FireServer(mouse.Hit.p)
end)

I’ve tried debugging and tweaking the code, but I haven’t been successful in getting the snowball to follow the mouse trajectory upon release. If anyone has experience with this or could provide guidance on how to properly implement mouse position-based throwing for a snowball in Roblox, I would greatly appreciate it.

I am not sure if this is the issue, but you misspelled “Activated”

1 Like

No, this is not the issue, but thanks!!!

I think setting the SnowBalls position to the mouse makes a bit more sense

local Handle = snowBall.Handle
        local newSnowBall = Handle:Clone()
        newSnowBall.Parent = workspace
        newSnowBall.CanTouch = false
        newSnowBall.CanCollide = true
        newSnowBall.Position = mouse.Hit.p

Upon testing, I have noticed a mistake in your script:

local throwDirection = (direction - newSnowBall.Position).unit

It seems that the newSnowBall position is higher than the direction value, which would result in a negative value, which makes it be thrown in the wrong position.

To fix this, you just have to change the order of the values, like this:

local throwDirection = (newSnowBall.Position - direction).unit

That way, it will result in a positive value and face the right position.

2 Likes