Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago
Edited 4 years ago

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)
0
You need to assign the value to the IntValue's Value property and not to the property hiimgoodpack 2009 — 4y
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. SethHeinzman 284 — 4y

1 answer

Log in to vote
2
Answered by 4 years ago
Edited 4 years ago

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.

0
Thanks for pointing out I haven’t connected them yet too lol. I completely was not seeing that for some reason SethHeinzman 284 — 4y
0
great answer. i wish everyone answered like this lol User#23252 26 — 4y
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. animorphs30 300 — 4y
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. SethHeinzman 284 — 4y
Ad

Answer this question