so, i maked a script that when i type in the chat “/e r” it deletes all the balls.
The problem is that when i type “/e r” it deletes only 1 ball and then i need to spam it to deletes all the ball. how do i make it so when i trype “/e r” it deletes all the ball and not only one?
Here my script:
local Table = {"AndreaEliteITA07", "DaLegendRO", "psitulasek2211", "tinashpp", "Pula23333", "LT_Snowy"}
local function Chat(plr,msg)
for i = 1, #Table do
if msg:lower() == "/r" and Table[i] then
if Table[i] == plr.Name then
if workspace:FindFirstChild("Ball") then
local Ball = workspace:FindFirstChild("Ball")
Ball:Remove()
end
end
end
end
end
game.Players.PlayerAdded:connect(function(plr)
plr.Chatted:connect(function(msg) Chat(plr,msg) end)
end)
A much better way is to parent all the balls to a folder and loop over the folder and delete all of the balls, which can also work with name overshadowing.
You can use a loop.
for _, v in pairs(workspace:GetChildren()) do
if v.Name == "Ball" then
v:Destroy()
end
end
As previously stated it’s going to be 100x more efficient to put it in a Folder, and then delete everything in the folder.
You can loop it
local Table = {“AndreaEliteITA07”, “DaLegendRO”, “psitulasek2211”, “tinashpp”, “Pula23333”, “LT_Snowy”}
local function Chat(plr,msg)
for i = 1, #Table do
if msg:lower() == “/r” and Table[i] then
if Table[i] == plr.Name then
Balls= game.Workspace:getChildren()
For ballz=1, #Balls do
if Balls[ballz].Name==“Ball” then
Balls[ballz]:Destroy()
end
end
end
end
end
end
end
game.Players.PlayerAdded:connect(function(plr)
plr.Chatted:connect(function(msg) Chat(plr,msg) end)
end)