Script inside beach ball not working after resetting

In serverstorage i have a beach ball with 2 scripts inside and by using print statements im pretty sure the localscript doesnt break but the other regular script isnt working after resetting. The ball gets cloned and put in the backpack and startergear when you purchase it with a GUI.
Explorer: Screen Shot 2021-09-02 at 12.29.16 PM
LocalScript (although it doesnt break)

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


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


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

Server script (The one that breaks)

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)

The server script is creating a collision group that’s already been created on the first use.
If I were you I’d check if the collision group has already been made or instead create it only on the first use.

Here’s the serverscript that should work.

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

local cooldown = false


local ps = game:GetService("PhysicsService")
if first_time == true then
   first_time = false
   ps:CreateCollisionGroup("Ball")
   ps:CreateCollisionGroup("Character")
   ps:CollisionGroupSetCollidable("Character", "Ball", false)
end



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)
1 Like

it worked but then when I reset it was the same and didnt do anything

use the collision group editor to make collision groups instead of creating them in the script, so remove the

ps:CreateCollisionGroup("Ball")
ps:CreateCollisionGroup("Character")
ps:CollisionGroupSetCollidable("Character", "Ball", false)

and just use the CG editor (under model > advanced)

1 Like

I was able to fix this problem with tools that animated but I don’t really know how to use collision groups and stuff so idk

they are stupidly confusing, i agree

1 Like