Why isn't this ball throw script working?

I have a tool in replicatedstorage that goes in the player’s backpack when they purchase the item and 2 scripts that are supposed to make the ball throw when the player clicks but they dont work.
Screen Shot 2021-06-28 at 11.52.44 AM This is the ball tool in replicatedstorage

This is the localscript inside:

local mouse = game.Players.LocalPlayer:GetMouse()
local remote = game.ReplicatedStorage.RemoteEvent

local tool = script.Parent

tool.Activated:Connect(function()
	remote:FireServer(mouse.Hit.p) 
end)

and this is the server script in serverscriptservice

local remote = game.ReplicatedStorage.RemoteEvent

remote.OnServerEvent:Connect(function(player, mouse)
	if not player.Character:FindFirstChild("Beach Ball") then return end

	local BeachBall = game.ReplicatedStorage["Beach Ball"]:Clone()
	BeachBall.Parent = workspace
    BeachBall.Position = player.Character["Beach Ball"].Handle.Position
	BeachBall.Velocity = (player.Character.Head.Position - mouse).LookVector * 350

	game:GetService("Debris"):AddItem(BeachBall, 10)
end)

Can someone help with this?

Have you tried debugging your code with print() statements or breakpoints to make sure it is all running when you click your mouse? Also your math seems a bit off, try something like (position1-position2).Unit*350. This is basically getting the directional vector between two positions (your character and your mouse), and normalizing it (making the vector have a magnitude of 1), and then changing the vectors magnitude to whatever you desire (350 in this case)

2 Likes

local remote = game.ReplicatedStorage.RemoteEvent

remote.OnServerEvent:Connect(function(player, mouse)
	if not player.Character:FindFirstChild("Beach Ball") then return end

	local BeachBall = game.ReplicatedStorage["Beach Ball"]:Clone()
	BeachBall.Parent = workspace
    BeachBall.Position = player.Character["Beach Ball"].Handle.Position
	BeachBall.Velocity = (mouse - player.Character.Head.Position).unit * 350

	game:GetService("Debris"):AddItem(BeachBall, 10)
end)

Use Unit instead, i already put that.
Explanation of Unit: Subtract from end position (mouse.Hit.p), start position (Head.Position), and then put .unit which will return vector3 direction, multiply it by 350 (or anything) and it should work. Try script i re-wrote. Let me know if it works

2 Likes

I tried it but no it still doesn’t work

Is there any errors in your output?

Does it shoot? can you send a video?

There is nothing in my output concerning the beach ball.

ill try but it says that it (the file) is too big but ill see also there’s nothing really to show I just click and it doesn’t shoot or anything