Make a script that delete all basketballs that is in the workspace

I used this

‘’-- Function to delete the balls
local function deleteBalls()
local practiceBalls = workspace:FindFirstChild(“PracticeBall”)
if practiceBalls then
– Loop through each ball and delete it
for _, ball in ipairs(practiceBalls:GetChildren()) do
ball:Destroy()
end
end
end

– Listen for chat messages
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(message)
if string.lower(message) == “/clear” then
deleteBalls()
end
end)
end)’’

Also the script in the a tool called PracticeBall which PracticeBall is in server storage i have a script that when the player says bb it goes in to workspace

The reason i really need this script is because lag if there is too much PracticeBalls in the server it could lag so i wanted to make a script that when the player say /Clear it would clear all balls in the workspace.

Why are you putting this in #help-and-feedback:platform-usage-support? Is there a problem with the script that you want help solving? That should go in #help-and-feedback:scripting-support.

Havent used dev forum in a bit sorry about that :sweat_smile:

2 Likes

That’s all right. What do you need help with?

local Workspace = game:GetService("Workspace")
local Players = game:GetService("Players")

local function deleteBalls()
	for _, v in ipairs(Workspace:GetDescendants()) do
		if v.Name == "PracticeBall" then
			v:Destroy()
		end
	end
end


Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(message)
		if string.lower(message) == "/clear" then
			deleteBalls()
		end
	end)
end)

I am guessing this has been written with ChatGPT. Here is the corrected code, try to see if this works! :blush:

1 Like

So this script im using is to delete a tool

The tool name is Practiceball which i have in the serverstorage

In game i want to type a command like /clear to delete the PracticeBall in workspace

The PracticeBall will be in the workspace because i have a script where when i said bb it goes into the workspace

It didnt work the i dont know if the problem is because i have another script that when i say bb the practice ball goes into the workspace im not sure.

local Workspace = game:GetService("Workspace")
local Players = game:GetService("Players")


Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(message)
		local LowerCaseMessage = string.lower(message)
		if LowerCaseMessage == "/clear" then
			for _, v in ipairs(Workspace:GetDescendants()) do
				if v.Name == "PractiseBall" then
					v:Destroy()
				end
			end
		end
	end)
end)

This should work. Let me know if it does not.

No error in the out put at all just a bunch of error plugins

Try the edited code above, and see if that works for you.

I see that you’ve have done a typo with practiseball being the typo i fixed it but its still not clearing the ball

have u tried the code here as this works for me…

Yes it doesnt work for me just for more detail the script is inside of the practiceball

Can you show the tool in server storage and what’s actually in the tool? Or you can give me the place file and I can fix the code for you.

Sure

Can you send me the game files? I don’t think we need to delete the PractiseBall tool.

Okay how do i send it to you the game file?

Press Ctrl Shift and S. Or you can just send me the script of the /bb commnd.

Code like this should work,

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(msg)
		if msg == "/clearballs" then
			print("clear")
			for i, v in pairs(workspace:GetChildren()) do
				if v:IsA(objecttype) and v.Name == "name" and v ~= nil then
					v:Destroy()
				end
			end
		end
	end)
end)

This is in a serverscript.

you should have taken into account what happened if the person says /ClearBalls, but this would work too.

1 Like