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

Why does my script return a nil even though I added a "If nil then return end" ? [Solved]

So this script copies a player's clothes to storage. It only works if they have both shirt and pants on. If they have no shirt or pants, it would return a nil. I even added a return end on line 3 and 9.

...
local shirt = character:FindFirstChild("Shirt"):Clone()
if shirt == nil then
	return
end
shirt.Parent = game.ReplicatedStorage.PlayerClothing
shirt.Name = player.Name .. "'s Shirt"
local pants = character:FindFirstChild("Pants"):Clone()
if pants == nil then 
	return 
end
pants.Parent = game.ReplicatedStorage.PlayerClothing
pants.Name = player.Name .. "'s Pants"

Please help?

2 comments

0

You forgot an end on line 7. lol

0

My mistake, I'll edit it.

1 answer

Nevermind, fixed my own problem:

local shirt = character:FindFirstChild("Shirt")
if shirt then
	local cloneshirt = shirt:Clone()
	cloneshirt.Parent = game.ReplicatedStorage.PlayerClothing
	cloneshirt.Name = player.Name .. "'s Shirt"
end
				
local pants = character:FindFirstChild("Pants")
if pants then
	local clonepants = pants:Clone()
	clonepants.Parent = game.ReplicatedStorage.PlayerClothing
	clonepants.Name = player.Name .. "'s Pants"
end

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