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

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

–[[
24k
enjoy lol
]]–

local function Chat(plr,msg) --Heres our Chat function
local char = plr.Character or plr.CharacterAdded:wait()
local humanoid = char:WaitForChild(‘Humanoid’)

while true do
if char:FindFirstChild(“PracticeBall”) then --removes spams–
wait()
break
else
if msg:lower() == “bb” then --If the Player types ‘bb’ then
if game:FindFirstChild(“ServerStorage”) and game.ServerStorage:FindFirstChild(“PracticeBall”) and plr and plr:FindFirstChild(“Backpack”) then --This will check to see if ServerStorage, Pass/Shoot, The Player, and the Player’s Backpack are existant
local GiveTool = game.ServerStorage[“PracticeBall”]:Clone() --This will clone the object
GiveTool.Parent = plr.Backpack
humanoid:EquipTool(GiveTool)
end --This ends the code for the second ‘if’ statement
end --This ends the code for the first ‘if’ statement
break
end
wait()
end

end --This ends the code for the ‘Chat’ function

game.Players.PlayerAdded:connect(function(plr) --Heres the PlayerAdded event; This will fire everytime a Player joins; The Player whom has joined will be identified as ‘plr’
plr.Chatted:connect(function(msg) Chat(plr,msg) end) --This connects the Player’s Chat to the ‘Chat’ function
end) --This ends the code for the ‘PlayerAdded’ event

Thats the bb script for the practice ball