Code support - Replicate baseball ball and throw

Hello, I would like to know how to fix my code to create a replica of my baseball ball and throw it (I need only the replicas to be thrown) how can I correct my code and do that?

image

– server script ball

local tool = script.Parent
tool.RemoteEvent.OnServerEvent:Connect(function(player, event)
	local mouse = player:GetMouse()
	local Handle = tool.Handle
	tool.Parent = workspace
	Handle.CFrame = CFrame.new(Handle.Position, event)

	local bv = Instance.new("BodyVelocity",Handle)
	bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
	bv.Velocity = tool.Handle.CFrame.LookVector * 70 -- Change the number if you want :D

	local vel = tool.Handle.CFrame.LookVector

	wait(.1)
	tool.Handle.BodyVelocity:Destroy()

	--- Adding the next part will result when they touch it then will like teleport to the position of the ball and like "take" it
	Handle.Touched:Connect(function(hit)
		if hit.Parent:FindFirstChild("Humanoid") then
			-- tool check
			local tnot = script.Parent.Parent.Bat
			local hastool = false
			local tool = script.Parent.Parent.Ball
			if player.Character:FindFirstChild(tool.Name) or player.Backpack:FindFirstChild(tool.Name)  then
				hastool = true
				Handle.Anchored = false
				wait(.1)
				Handle.Anchored = true
				Handle.Anchored = false
				hastool = false
			elseif player.Character:FindFirstChild(tnot.Name) or player.Backpack:FindFirstChild(tnot.Name) then
				print("You already have the ball, you can't have the bat too.")
			end -- end
		end
	end)
end)

script.Parent.Equipped:Connect(function()
	for i = 0, -4, -.5 do
		script.Parent.GripPos = Vector3.new(0,i,0)
		wait()
	end

	for i = -4,0,.5 do
		script.Parent.GripPos = Vector3.new(0,i,0)
		wait()
	end
end)
local tool = script.Parent:Clone() -- copy the object

or

local mouse = player:GetMouse()
local Handle = tool.Handle:Clone() -- copy the actual ball instead of the tool
Handle.Parent = workspace
Handle.CFrame = CFrame.new(Handle.Position, event)

it gave me this error here

You cloned the Handle, and placed a BodyVelocity inside that Clone, then on line 20. You are looking for the BodyVelocity inside the Tool Handle, the First one that existed, and not inside the Second one, the one cloned, the one with the BodyVelocity.

So u get that error. cause theres no BodyVelocity inside the Tool’s handle. Actually the Handle with the BodyVelocity (the cloned one) is parented to workspace.

And I have a little doubt about ur code. This is a server script right?
Trying to access the Player:GetMouse() is only possible on LocalScripts. Its not causing you errors?..
Check the hub, should only be done on ClientSide LocalScripts, and your script is in server side…


1 Like