How to find a int value in player and reference it

This is the script which fires when I click on a part. However, there is no error but it prints nope which i assume means player:FindFirstChild(“Color” doesnt exist.

local part = script.Parent
local click = part.ClickDetector

local function onClicked(player)
	local color = player:FindFirstChild("Color")
	if color then
		print("found color thingiemabob")
	else
		print("nope")
	end
end

click.MouseClick:Connect(onClicked)

This is the code which gives the player an int value

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(Character)
		local Value = Instance.new("IntValue",Character)
		Value.Name = "Color"
		Value.Value = 0
	end)
end)

Thank you!

player.Character:FindFirstChild("Color")

You create a Color inside the player’s character. When you click, you are not looking for it in the player's character itself, but in the player's instance. That was the problem.

image
not equivalent to
image

so how am i supposed to find it? (im new at scripting :frowning: )

In my reply, I gave you the answer on the first line lol.
However.

local part = script.Parent
local click = part.ClickDetector

local function onClicked(player)
	local color = player.Character:FindFirstChild("Color")
	if color then
		print("found color thingiemabob")
	else
		print("nope")
	end
end

click.MouseClick:Connect(onClicked)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.