Hello again, sorry for posting back here so soon, but I've ran into another issue.
Essentially, this is a part 2 to a previous post I made regarding the spawns in my game, of which you can find here.
Our game's biggest problem is people spawning in all the robots, and despawning other people's robots. With help from a lovely member on here, that problem has been solved. However we have since ran into a new problem that I thought would be easy to fix, but is far from it.
If a player spawns a bot and then leaves the server, the bot stays in and nobody can despawn it, this can be repeated multiple times and can cause immense lag and disruption in the server.
This is the current script for the spawners:
local Robot = game.ServerStorage:FindFirstChild("Aegis",true)
local Spawned = script.Parent:FindFirstChild("Spawned",true)
function onClicked(player)
BotSpawned = player.BoolValue
BotBeingUsed = player.StringValue
if Spawned.Value == false and BotSpawned.Value == false then
BotBeingUsed.Value = 'Aegis'
BotSpawned.Value = true
backup = Robot:clone()
backup.Parent = workspace
backup:makeJoints()
Spawned.Value = true
script.Parent.BrickColor = BrickColor.new("Really red")
elseif Spawned.Value == true then
if BotBeingUsed.Value == 'Aegis' then
BotBeingUsed.Value = 'None'
BotSpawned.Value = false
backup:Destroy()
Spawned.Value = false
script.Parent.BrickColor = BrickColor.new("Lime green")
end
end
end
while Spawned.Value == true do
for i, player in pairs(game.Players:GetPlayers()) do
if player.StringValue.Value ~= 'Aegis' then
backup:Destroy()
Spawned.Value = false
script.Parent.BrickColor = BrickColor.new("Lime green")
break
else
wait()
end
end
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)
The part from "While Spawned.Value == true do" and blow is my attempt to fix said issue, however it has yet to be successful, if someone could help me out to fix this one problem, the game's biggest issue can be solved.
I am quite new to this level of scripting, so excuse me if I don't quite comprehend things right/have bad code.
Thank you for reading.

6 comments
Also, you could enable the bot for spawning in the script later blah blah
wth your game is growing sonic it's 70k+ visits :scream: :how:
XAP COMING IN WITH THE CLUTCH AGAIN THANK YOU
i never get more than 200 visit in my game lol how wth
we've had a small playerbase in our old game back when we were just some young kids fooling around doing whatever we could, and we were tapping into a player base that had yet to be fully taken yet
i think what got us such a big visit amount was the timing of the tv show, as when we did a BIG update that made the game more playable, it was when the tv show season ended and people wanted more robot destruction