Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Code not removing "Clothe" from the player?

The Goal For This Script Is To Run A Simple Game Loops, And Then Pick A Random Player. The issue is, the code seems to completely skip the part of removing all the players "clothing". But will continue with the loop for 'Game'.

--//Services//--
local players = game:GetService('Players')
--//Variables//--
local timeInt = 60
local intTime = 60
local pretime = 10

--//Round Objects//--
local status = game.ReplicatedStorage.Status
local spawnPoints = game.Workspace:FindFirstChild('Spawnpoints')
local lobbySpawns = game.Workspace:FindFirstChild('Lobbyspawns')

--//Main//--
while wait() do
	--//Return To Lobby//--
	for i,Player in pairs (players:GetPlayers()) do
		if Player.Character then
			Player.Character:SetPrimaryPartCFrame(lobbySpawns:FindFirstChild('Point' ..i).CFrame + Vector3.new(0,3,0))
		end
	end
	--//Intermission Time//--
	for i=intTime,1,-1 do
		wait(1)
		status.Value = 'intermission'
	end
	--//Bring Players To Map//--
	for i,Player in pairs (players:GetPlayers()) do
		Player.Character:SetPrimaryPartCFrame(spawnPoints:FindFirstChild('Point' ..i).CFrame + Vector3.new(0,3,0))
	end	
	--//Signal Prematch//--
	for i=pretime,1,-1 do
		status.Value = 'prematch'
		wait(1)
	end
	
	local currentPlayers = players:GetPlayers()
	local firstInfected = currentPlayers[math.random(#currentPlayers)]
	for _, child in pairs(firstInfected:GetChildren()) do
    if child:IsA('Hat') then
        child:Destroy()
     end
    if child:IsA('ShirtGraphic')then
        child:Destroy()
    end
	if child:IsA('Pants')then
        child:Destroy()
    end
    if child:IsA('Shirt')then
        child:Destroy()
    end
    if child.Name == "Torso" then
        for _, TorsoChild in pairs(child:GetChildren()) do
            if TorsoChild:IsA('Decal')then
                TorsoChild:Destroy()
            end
        end
    end
end 
	
	--//Signal Match//--
	for i=timeInt,1,-1 do
		wait(1)
		status.Value = 'game'
	end
end

Thanks!

1 answer

local firstInfected = currentPlayers[math.random(#currentPlayers)]

That is because that is the player object, and not that player's character. Fix:

local firstInfected = currentPlayers[math.random(#currentPlayers)].Character

Also, I would recommend using Accoutrement(All hats, accessories, etc.) instead of hat. So,

if child:IsA('Accoutrement') then
	child:Destroy()
end

instead of

if child:IsA('Hat') then
	child:Destroy()
end

This discussion is preserved as it was. New answers, comments, and votes are closed.