Making a practicing game and this is bad
so this is the error
Bot_4 is not a valid member of Workspace "Workspace" - Server - BotServer:26
13:29:35.367 Stack Begin - Studio
13:29:35.367 Script 'ServerScriptService.BotServer', Line 26 - Studio - BotServer:26
13:29:35.367 Stack End - Studio
If it’s nil it breaks the code and here is the code
-- Variables
local BotEvent = game.ReplicatedStorage.Events.BotEvent
-- Delays
local Debounce = false
local DebounceDelay = 5
local function Yield(s)
local t = tick()
while tick() - t < s do game:GetService("RunService").Stepped:Wait() end
return tick() - t
end
BotEvent.OnServerEvent:Connect(function(Player, BotStatus)
local BotStorage = game.ServerStorage.Bots
if BotStatus == true then
-- add a bot to workspace
local randomized = math.random(1, 5)
local Bot = BotStorage["Bot_"..randomized]
Bot:Clone().Parent = workspace
elseif BotStatus == false then
-- remove bot from workspace
local randomized = math.random(1, 5)
if workspace["Bot_"..randomized] then -- checking doesn't even work anymore
local Bot = workspace["Bot_"..randomized]
Bot:Destroy()
else
print('none')
end
end
end)
is there a way to see if the selected object or I can just destroy 1 Bot from workspace with randomization any tips?