Folder Deletion Issues

I want to clear the TeamScript folder before I clone a new folder into TeamScript

Getting Errors that it is not a Valid Member, because it hasn’t bean created yet.
I’ve tried a few times to write this a different way but can’t figure it out

Here is where the issue is:

if Character.TeamScript.Spectators then
		Character.TeamScript.Spectators:Destroy()
	elseif Character.TeamScript.Guardians then
		Character.TeamScript.Guardians:Destroy()
	elseif Character.TeamScript.Raiders then
		Character.TeamScript.Raiders:Destroy()
	else
		print("ERROR:NO FOLDERS TO DELETE")
	end
  02:01:22.998  Really blue  -  Client - Team Change Detector:15
  02:01:23.014  Spectators is not a valid member of Folder "Workspace.zazy0909.TeamScript"  -  Server - TEamtest:17

And here is the whole script if needed:

local RS = game:GetService("ReplicatedStorage")
local TeamSwitch = RS:WaitForChild("TeamSwitch")

local RED = BrickColor.new("Really red")
	
local BLUE = BrickColor.new("Really blue")
	
local WHITE = BrickColor.new("White")


TeamSwitch.OnServerEvent:Connect(function(player, Team)
	
	local Character = player.Character or player.CharacterAdded:Wait()
	--print(TeamSwitch)
	--print(player)
	--print(Team)	

	if Character.TeamScript.Spectators then
		Character.TeamScript.Spectators:Destroy()
	elseif Character.TeamScript.Guardians then
		Character.TeamScript.Guardians:Destroy()
	elseif Character.TeamScript.Raiders then
		Character.TeamScript.Raiders:Destroy()
	else
		print("ERROR:NO FOLDERS TO DELETE")
	end

	print(player,"is on",Team)
	
	if Team == WHITE then
		local WhiteClone = RS.Teams.Scripts.Spectators:Clone()
		wait()
	WhiteClone.Parent = Character.TeamScript
		
		
	elseif Team == BLUE then
		local BlueClone = RS.Teams.Scripts.Guardians:Clone()
		wait()
	BlueClone.Parent = Character.TeamScript
	
		
	elseif Team == RED then
		local RedClone = RS.Teams.Scripts.Raiders:Clone()
		wait()
	RedClone.Parent = Character.TeamScript
	
		
	else
		print("ERROR:PLAYER TEAM NONE")
	
	end
	
end)


try using this

if Character:WaitForChild("TeamScript", 60):FindFirstChild("Spectators") then
		Character.TeamScript.Spectators:Destroy()
	elseif Character:WaitForChild("TeamScript", 60):FindFirstChild("Guardians") then
		Character.TeamScript.Guardians:Destroy()
	elseif Character:WaitForChild("TeamScript", 60):FindFirstChild("Raiders") then
		Character.TeamScript.Raiders:Destroy()
	else
		print("ERROR:NO FOLDERS TO DELETE")
	en
1 Like

thank you, worked like a charm

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.