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

Does anyone know what's wrong with this .Changed:Connect()?

So I'm trying to change the skin color of the person and instead of having a bunch of code I decided to create an Instance IntValue that changes when the user clicks a different skin Icon and that calls a Changed:Connect function to change the players skin color.

So I'm Getting this error: 13:53:54.841-Players.SoSurfsUpSeth.PlayerGui.StartMenu.CreateCharacter.CreateCharacter:13: attempt to index upvalue 'SkinColorNotifier' (a number value)

Here is this code:

local player = game.Players.LocalPlayer
local Character = player.Character
local SkinColorList = player.PlayerGui.StartMenu.CreateCharacter.SkinColor.SkinColor.SkinColorList
local SkinColorSelected = Color3.new(SkinColorList.White.BackgroundColor3)
local SkinColorNotifier = Instance.new("IntValue")

SkinColorNotifier.Changed:Connect(function(player)
	Character.Head.BrickColor = BrickColor.new(SkinColorSelected)
end)
-- Skin Color Selection
local function White()
	SkinColorSelected = SkinColorList.White.BackgroundColor3
	SkinColorNotifier.Value = 1
end
local function WhiteTan()
	SkinColorSelected = SkinColorList.WhiteTan.BackgroundColor3
	SkinColorNotifier.Value = 2
end
local function Tan()
	SkinColorSelected = SkinColorList.Tan.BackgroundColor3
	SkinColorNotifier.Value = 3
end
local function PinkTan()
	SkinColorSelected = SkinColorList.PinkTan.BackgroundColor3
	SkinColorNotifier.Value = 4
end
local function DarkPinkTan()
	SkinColorSelected = SkinColorList.DarkPinkTan.BackgroundColor3
	SkinColorNotifier = 5
end
local function OrangeTan()
	SkinColorSelected = SkinColorList.OrangeTan.BackgroundColor3
	SkinColorNotifier = 6
end
local function LightBrown()
	SkinColorSelected = SkinColorList.LightBrown.BackgroundColor3
	SkinColorNotifier = 7
end
local function Brown()
	SkinColorSelected = SkinColorList.Brown.BackgroundColor3
	SkinColorNotifier = 8
end

SkinColorList.White.MouseButton1Click:Connect(White)
SkinColorList.White.MouseButton1Click:Connect(WhiteTan)
SkinColorList.White.MouseButton1Click:Connect(Tan)
SkinColorList.White.MouseButton1Click:Connect(PinkTan)
SkinColorList.White.MouseButton1Click:Connect(DarkPinkTan)
SkinColorList.White.MouseButton1Click:Connect(OrangeTan)
SkinColorList.White.MouseButton1Click:Connect(LightBrown)
SkinColorList.White.MouseButton1Click:Connect(Brown)

2 comments

0

You need to assign the value to the IntValue's Value property and not to the property

0

Could you explain what you mean? I fixed the functions that didn't have SkinColorNotifier.Value cause I noticed that earlier. It still doesn't work and has the same error.

1 answer

✓ Accepted answer

#1. Look at the bottom, where all the events are being connected. See that they all connect to the exact same Gui object when clicked? This means that every function there is being run every time you click, making a large majority of this obsolete sadly.

#2. This isn't exactly a coding problem, more of a future warning. You have the parameter of the changed connection as "player". Now, this doesn't cause any issues to your code, due to the fact that the parameter isn't used, but in the case you want to ever use it in the future, I'd recommend you change its name from "player" to "property"

#3. This is where the technical coding issue is. You never specified a parent for the SkinColorNotifier. It's essentially in limbo right now, making it undetectable for the script. To change this, simply set the parent of the Instance to something.

4 comments

0

Thanks for pointing out I haven’t connected them yet too lol. I completely was not seeing that for some reason

0

great answer. i wish everyone answered like this lol

0

Np. I think it's best to help out in every way. When I was still learning there were literal moments where I spent 5+ hours debugging a single script. I'm aware these kinds of things are a pain, so I'm glad to help.

0

Yeah I study computer science in college and I'm on my senior year. I have spent 4 hours staring at code only to realize I set my pointer to null before I freed the memory.

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