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

If statement not ignoring nonexistant Decal?

if part.Decal then
	part.Decal.Texture = "rbxassetid://272632642"
else
	print('asd')
end

Error: Decal is not a valid member of Part

I made a if statement that replaces the decal texture if theres an actual decal if no decal is present inside the part then it'll just print 'asd' but it is not actually printing 'asd' instead it is making an error

How am I supposed to fix this?

1 answer

✓ Accepted answer

Use :FindFirstChild("Decal")

if part:FindFirstChild("Decal") then
	part.Decal.Texture = "rbxassetid://272632642"
else
	print("Decal is not there")
end

Because currently, it's not doing a Boolean value. :FindFirstChild() can be used in multiple ways, one way is checking if something is there, if there's not then you can do something else.

For example.

if game.Players.LocalPlayer.PlayerGui:FindFirstChild("ScreenGui") then -- Boolean
	print("Player Already Has A ScreenGui")
else
	local screenGui = script.Parent:FindFirstChild("ScreenGui"):Clone() -- Finding an object
	screenGui.Parent = game.Players.LocalPlayer.PlayerGui
end

Like I said, there's many ways to use multiple functions. All you have to do is explore.

2 comments

0

ty man

0

No problemo.

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