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

What's wrong in my script which giving decal on torso?

Hello! I made script which giving decal on torso when you gonna click brick, but it's not working any ideas what's wrong?

This is this script

local brick = script.Parent
local decal = brick:findFirstChild("Decal")

script.Parent.ClickDetector.MouseClick:connect(function(player)
	local humanoid = player.Parent:findFirstChild("Humanoid")
	local torso = player.Parent:findFirstChild("Torso")
	if torso ~= nil and humanoid ~= nil then
		local shirt = player.Parent:findFirstChild("Shirt Graphic")
		if shirt ~= nil then
			shirt.Graphic = decal.Texture
		else
			local altshirt = torso:findFirstChild("roblox")
			if altshirt ~= nil then
				altshirt.Texture = decal.Texture
			else
				print("Torso found. Shirt not found. Assumed to be a robot.")
			end
		end
	else
		print("Not a valid person! T-Shirt cannot be changed!")
	end
end)

1 answer

✓ Accepted answer

The ClickDetector.MouseClick event passes a player as it's one and only argument.

The problems I see are in lines 5 and 6, where you try to find Humanoid and Torso as a child of the parent of the player. (which is essentially trying to find the player's humanoid and torso in game.Players)

There is a property of the player that refers to the player's character in the workspace. To reference it, use player.Character instead of player.Parent.

Relevant links:

ClickDetector.MouseClick

player.Character

1 comment

1

Works, thank you

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