‘’-- 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.
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!
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)
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)