Football shot with mouse aim

  1. What do you want to achieve?
    I want the ball to shoot the way where your mouse cursor is, but only to your front. So you cant shoot the ball backwards.

  2. What is the issue?
    I cant reference mouseHit accordingly and dont know all the steps

  3. What solutions have you tried so far?

I have researched a lot, but couldnt find an answer, and I basically just tried and error

Server script:

 shot = game.ReplicatedStorage.Remotes.ShootBall.OnServerEvent:Connect(function(player, KickMeter, MouseHit) -- KickMeter
	local PlrStats = player:WaitForChild("PlrStats")
	local Power = PlrStats.Power.Value
	

		local anim = animations.Kick
		player.Character.Humanoid.Animator:LoadAnimation(anim):Play()
	wait(0.52)
	if attached == true then
		ball.Position = ball.Position + Vector3.new(0.5,-0.3,-0.15)
		if ball.Parent.Name == "GetBallHitbox" then
			ball.CanCollide = true
			ball.Parent:WaitForChild("WeldConstraint"):Destroy()
		end
		ball.Parent = workspace
		ball.CanTouch = false
		ball.Velocity = player.Character.HumanoidRootPart.CFrame.LookVector * ((Power + 65) * (KickMeter / 10))
		speeding = true
		wait(0.5)
		ball.CanTouch = true
		attached = false
		ball.CanCollide = true
		
		debounce = false
		
		print((Power + 65) * (KickMeter / 10))
		
	end
end)

Then I send this from a local script
game.ReplicatedStorage.Remotes.ShootBall:FireServer(KickMeter.Value, mouse.Hit.Position)
2 Likes

As you can see, I have
local Power = PlrStats.Power.Value
I want to use that as the power of the ball, where the higher it is, the faster the ball will go





You need to convert the mouseHit from the client onto the server, in order to use it.
```workspace.CurrentCamera.CFrame:PointToObjectSpace(mouseHit.Position)

This will convert the mouse hit into the server’s camera’s object space, and you can use it to calculate the direction of the ball’s velocity.

1 Like

I dont understand what you said in the start of your reply, and I dont know how to use the script you sent lol. Could you perhaps elaborate a bit?

1 Like