Why isn't this beach 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:

-- Client -- 
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

-- Server --
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.AssemblyLinearVelocity = (mouse - player.Character.Head.Position).unit * 350

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

Can someone help with this?

4 Likes
-- Server --
local remote = game.ReplicatedStorage.RemoteEvent

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

	local BeachBall = player.Character["Beach Ball"].Handle:Clone()
	BeachBall.CanCollide = true
	BeachBall.Parent = workspace
	
	local BodyVelocity = Instance.new("BodyVelocity")
	BodyVelocity.Velocity = (mouse - player.Character.Head.Position).Unit * 30
	BodyVelocity.Parent = BeachBall

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

I tried it but it still didn’t work

LOCAL SCRIPT:

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

SERVER SCRIPT:

local remote = game.ReplicatedStorage.RemoteEvent

remote.OnServerEvent:Connect(function(player, mouseHit)
	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.AssemblyLinearVelocity = (mouseHit.p - player.Character.Head.Position).unit * 350

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

yea i tried it its still not working

Note: This may or may not be helpful.

Hey, so if your planning on adding physics to this beachball. Then I would highly recommend using Bezier Curves.

I’ve made my own gun with implemented physics too it.

Make a new tool make a handle for it, and put this code inside of a local script inside. You’ll understand what I’m talking about once you do it. I made this script myself so yea.



function c(t, p0, p1, p2)
	return (1 - t)^2 * p0 + 2 * (1 - t) * t * p1 + t^2 * p2	
end

script.Parent.Activated:Connect(function()
	local Mouse = game.Players.LocalPlayer:GetMouse()
	local Part = Instance.new("Part"); Part.Color = Color3.fromRGB(255, 85, 0); Part.Shape = "Ball"; Part.Size = Vector3.new(1,1,1); Part.Anchored = true; Part.CanCollide = false
	Mouse.TargetFilter = Part
	local x,y,z = Mouse.Hit.X, Mouse.Hit.Y, Mouse.Hit.Z
game.Debris:AddItem(Part, 5)
	local v = (script.Parent.Handle.Position + Mouse.Hit.Position)/2 + Vector3.new(0,y + 10,0)
	for i = 0, 1, 0.05 do
		Part.Parent = game.Workspace
		local pos = c(i,script.Parent.Handle.Position,v,Vector3.new(x,y,z))
		Part.Position = pos
	
		wait()
	end
	Part.Position = Part.Position - Vector3.new(0,1,0)
end)

ok thank you ill take a look and consider it!

1 Like