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

Player is not a valid member of frame?

Asked by
Mrt94 7
4 years ago
Edited 4 years ago

I am making a script where when a player click a button in a GUI it will change they're name color on a GUI to lime green. The color changing works when i manually put the command in and replace "Player" with my name. Please help.

It is saying this "Player is not a valid member of Frame"

local Button = script.Parent
local VoteColors = game.StarterGui.AdminGUI.AGUI.Frame.Frame.PlayersComboBox

local Player = game.Players.LocalPlayer.Name
local PlayerVoted = game.Players.Player.PlayerGui.AdminGUI.AGUI.Frame.Frame.PlayersComboBox.List.Player

Button.MouseButton1Click:Connect(function() 
    print("WORKING")
    PlayerVoted.TextColor3 = Color3.new(0, 255, 0)
end)

YOU MIGHT NEED TO CLICK "VIEW SOURCE" TO SEE CODE PROPERLY!

UPDATE: Here is the fixed code! (Thank you Claervoyance)

local Button = script.Parent
local VoteColors = game.StarterGui.AdminGUI.AGUI.Frame.Frame.PlayersComboBox

local Player = game.Players.LocalPlayer
local PlayerVoted = game.Players[Player.Name].PlayerGui.AdminGUI.AGUI.Frame.Frame.PlayersComboBox.List[Player.Name]

Button.MouseButton1Click:Connect(function() 
    print("WORKING")
    PlayerVoted.TextColor3 = Color3.new(0, 255, 0)
end)
0
You're reinventing the wheel by indexing line 4's variable into line 5. Line 4 is, therefore, completely unnecessary. DeceptiveCaster 3761 — 4y

1 answer

Log in to vote
0
Answered by
Hypgnosis 186
4 years ago

It's trying to find your Player in the Frame. In order to index something in the Frame with the Player's name, you have to write the index as such: Frame[Player.Name]

Also, I took out the name from your Player variable. Just write Player.Name when you need to access the name.

So, here is (hopefully) corrected code:

local Button = script.Parent
local VoteColors = game.StarterGui.AdminGUI.AGUI.Frame.Frame.PlayersComboBox

local Player = game.Players.LocalPlayer
local PlayerVoted = game.Players.Player.PlayerGui.AdminGUI.AGUI.Frame.Frame.PlayersComboBox.List[Player.Name]

Button.MouseButton1Click:Connect(function() 
    print("WORKING")
    PlayerVoted.TextColor3 = Color3.new(0, 255, 0)
end)
0
Click view source to see it all. Hypgnosis 186 — 4y
0
This answer is EXACTLY what i was looking for. However your code is wrong in one area, i learned from you when you put [Player.Name] and that helped me fix one area. You put "game.Players.Player.PlayerGUI" at the begining, it needed to be "game.Players[Player.Name].PlayerGUI" THANK YOU! Mrt94 7 — 4y
0
Oh, glad you figured it out. Hypgnosis 186 — 4y
Ad

Answer this question