Beach ball script not working

I have a tool in replicatedstorage that goes in the player’s backpack when they purchase the item and some scripts inside. When you click to throw the ball, it is not throwing or doing anything. Here is my explorer: Screen Shot 2021-07-21 at 7.35.11 PM (In replicatedstorage)
BallServer:

local tool = script.Parent
local re = tool:WaitForChild("BallRE")

local cooldown = false


local ps = game:GetService("PhysicsService")
ps:CreateCollisionGroup("Ball")
ps:CreateCollisionGroup("Character")
ps:CollisionGroupSetCollidable("Character", "Ball", false)


re.OnServerEvent:Connect(function(plr, mouseHit)
	
	local char = plr.Character
	local hum = char:FindFirstChild("Humanoid")
	
	
	if hum and not cooldown then

		cooldown = true
		
		hum.Jump = true
		
		local ballClone = tool.Handle:Clone()
		ballClone.Transparency = 0
		tool.Handle.Transparency = 1
		
		
		for i, descendant in pairs(plr.Character:GetDescendants()) do
			if descendant:IsA("BasePart") then ps:SetPartCollisionGroup(descendant, "Character") end
		end
		ps:SetPartCollisionGroup(ballClone, "Ball")
		
		
		local velocity = mouseHit.Position + Vector3.new(0, game.Workspace.Gravity * 0.5, 0)
		ballClone.Velocity = velocity
		
		ballClone.CanCollide = true
		ballClone.Parent = workspace
		
		
		game:GetService("Debris"):AddItem(ballClone, 2)
		
		wait(3)
		ballClone.Velocity = Vector3.new(0, 0, 0)
		tool.Handle.Transparency = 0
		cooldown = false
	end
end)

BallClient:

local tool = script.Parent
local re = tool:WaitForChild("BasketballRE")


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


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

Can someone help me with this?

1 Like

What exactly is “not working”? What errors are you getting? It will be way easier to help you having more information.

3 Likes

I checked for errors and didn’t see any. The issue is that when you click it doesn’t throw the ball or anything but if I put the ball in workspace and just pick it up like that it works but if I put it in replicatedstorage and the player purchases it and tries to use it it doesn’t throw when you click it

1 Like

In the ball client script on line 2, it looks like you are using an incorrect name. Instead of “BasketballRE,” shouldn’t you be using “BallRE?” image

2 Likes

He wouldn’t get an error because he’s using :WaitForChild, so thats probally right

2 Likes

oh uh oops I’ll try that when I can and let yk if it works
It was a basketball and then I wanted it to be a beach ball and I forgot to change the name so that’s why

2 Likes

I changed it to BallRE in the script, still doesn’t seem to shoot or really do anything when clicked tho

1 Like

Try adding a BodyVelocity in the ball and do

ballClone.BodyVelocity.Velocity = velocity

3 Likes


Thats what I changed but it still doesn’t work
Also it worked before when I put the tool in workspace, picked it up and tried it but now when I want it to be purchased and parented to the backpack when its purchased it doesn’t seem to be working

2 Likes

Can you provide the script for purchasing the ball and giving it to the player? The problem might be in there and not the throwing script, if it works when the player picks it up from the workspace.

2 Likes

Okay so for purchasing there is a LocalScript inside the purchase button and here it is (Shells is my game’s currency)
Screen Shot 2021-07-27 at 2.00.13 PM :

local player = game.Players.LocalPlayer
local Ball = game.ReplicatedStorage["Beach Ball"]:Clone()

script.Parent.MouseButton1Click:Connect(function()
	if player.leaderstats.Shells.Value >= 150 then
		-- Checks if player has enough shells
		game.Workspace.PurchaseSuccessful:Play()
		game.ReplicatedStorage.PurchaseBall:FireServer(150)
		-- Fires RemoteEvent that charges player
		Ball.Parent = player.Backpack
	else
		game.Workspace.PurchaseFailed:Play()
		script.Parent.Text = ("Insufficient funds!")
		wait(3)
		script.Parent.Text = ("Purchase for 150 Shells...")
	end
end)

In ReplicatedStorage, there is a RemoteEvent called PurchaseBall.
Screen Shot 2021-07-27 at 2.01.46 PM
In ServerScriptService, there is a script that handles all the things that charge the player. I have all my purchases in this script, but I’ll show the ball one as well as a screenshot if you want the entire script.

game.ReplicatedStorage.PurchaseBall.OnServerEvent:Connect(function(player,amount)
	player.leaderstats.Shells.Value= player.leaderstats.Shells.Value -150
end)

2 Likes

It’s not the problem but in your server script you should subtract by amount not 150

2 Likes

oh would that make a difference because I think I tried that once but it didn’t work so I just used 150 instead

1 Like

I’m not completely sure if this will work, but according to the developer hub, you should put tools inside of ServerStorage, not ReplicatedStorage.

Here is the link to the article if you need it. The problem might also possibly be that you are putting the tool inside the backpack from a local script and not a server script.

2 Likes

I originally did server storage but it didn’t work so I had to use replicatedstorage instead

2 Likes

ill try server storage again and make edits to the script and see if it’ll work

2 Likes

I think im just gonna use replicatedstorage because its the only way that works for me atm but idk why its not shooting that way

2 Likes

I noticed that when I equip the tool it goes out of my players backpack and back in when I unequip it. Could this have anything to do with the problem considering the scripts are in that tool?
Not equipped:


Equipped:

2 Likes

It does seem strange that the ball is removed from the backpack when equipped. Maybe try moving the BallServer script to ServerScriptService and editing the line that finds the ball accordingly.

2 Likes

It doesn’t work from server storage because local scripts can’t access server storage so it can’t clone it

1 Like