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

How do I detect if something is gone/doesn't exsist?

I've been trying to script, a simple script, that changes the players Accessories and Limbs to a different Material, which was a huge success.

However, I know that players don't always wear clothes, but instead use Body Colors. So I'm trying to update my script to detect if the players are wearing anything, and if they aren't, to cloth them with a shader outfit, so the Material doesn't show on the players.

local shirt = script:WaitForChild("ShadowShirt")

local function Checkshirt(character)
	for i, object in pairs(character:FindFirstChild()) do
		if object:IsA("Shirt") then --Breaks here sometimes
			print("All Good here!")
		elseif character.Shirt ~= nil then --And here most of the time
			shirt:Clone().Parent = character
		end
	end
end

How do I go about scripting the detection of the shirt, and if there is no shirt, verifying that the shirt doesn't exsist?

3 answers

✓ Accepted answer

or you could do this

local shirt = script:WaitForChild("ShadowShirt")

local function Checkshirt(character)
    if character:FindFirstChild("Shirt") then--ye it just looks after the shirt and if it finds then
            print("All Good here!")--this happens
        else  --otherwise
            shirt:Clone().Parent = character--this happens
end

1 comment

0

Thanks alot! this did the trick.

Use FindFirstChildOfClass (Say that three times fast) to check if there's any Shirt in the character

function checkShirt(char)
  return character:FindFirstChildOfClass("Shirt")
end

As a bonus, that function also returns the shirt if it exists. How useful.

2 comments

0

i said it 3 times fast no problem lol

0

uhhuh.

Thanks for your help, Final product;

print("Only you can prevent Shadowmap Shiny Avatars")
print("No Clothes? Patched")--v1.0.1

local players = game:GetService("Players")

local shirt = script:WaitForChild("ShadowShirt")
local pants = script:WaitForChild("ShadowPants")

local function Checkskin(character)
	for i, object in pairs(character:GetChildren()) do
		if object:IsA("MeshPart") or object:IsA("Part") then
			object.Material = "Fabric"
		end
	end
end

local function Checkshirt(character)
	    if character:FindFirstChild("Shirt") then
	            print("All Good here!")
	        else
	            shirt:Clone().Parent = character
				print("No Shirts, No Service")
	end
end


local function Checkpants(character)
	    if character:FindFirstChild("Pants") then
	            print("And Here!")
	        else
	            pants:Clone().Parent = character
				print("No Rules! ...One Rule!")
	end
end

players.PlayerAdded:connect(function(player)
	player.CharacterAdded:connect(function(character)
		player.CharacterAppearanceLoaded:wait()
		Checkskin(character)
		Checkshirt(character)
		Checkpants(character)

	end)
end)

--[[
By Yezai, Assisted by Gameplayer365247v2
--]]

3 comments

0

I did one for accessories aswell, because I hate shiny avatars with shadowmap lighting

0

can you accept my answer

0

Ofcourse, I didn't notice that option yesturday, accepted your answer though.

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