function unselect() local children = script.Parent:GetChildren() for i = 1,#children do if children[i].ClassName == "ImageButton" and children[i].Chosen.Value == true then print("Unselected " .. children[i].Name) children[i].Chosen.Value = false children[i].BorderSizePixel = 2 children[i].BorderColor3 = Color3.fromRGB(35,35,35) children[i]:TweenSize(UDim2.new(0, 80, 0, 80), "In", "Quad", .2) end end end function pselect(pokeID) local clicked = pokeID.Parent.Parent script.Parent.PokemonID.Value = pokeID unselect() clicked.Chosen.Value = true clicked.BorderSizePixel = 3 clicked.BorderColor3 = Color3.fromRGB(57,141,230) clicked:TweenSize(UDim2.new(0, 90, 0, 90), "Out", "Quad", .2) print(pokeID) print(clicked.NameLabel.Text) end script.Parent.P151.MouseButton1Click:connect(pselect(script.Parent.P151.PokemonID.Value))
There's a bit of extra code there, but I figured you need to see it all, just in case. The problem is occurring on line 15,
local clicked = pokeID.Parent.Parent
The error message I get is:
Players.pokemon_origin.PlayerGui.ScreenGui.PokemonList.LocalScript:19: attempt to index local 'pokeID' (a number value)
The value I'm passing is an integer, it's just 151. The error seems to be in the passing of the value, because it gives an error the first time my script tries to use the passed value (151). If I missed out any information, please ask. Thanks.
EDIT: It clipped off the last line of the code, here it is: script.Parent.P151.MouseButton1Click :connect(pselect(script.Parent.P151.PokemonID.Value))
Firstly, you say that the value being passed is an integer, but your function appears to expect an object.
Secondly, to pass arguments to a function connected to an event, you need to enclose the call in an anonymous function, like this:
script.Parent.P151.MouseButton1Click:connect(function() pselect(script.Parent.P151.PokemonID.Value) end)
Your existing code would call pselect
with those arguments, then take the return value (if any) and call connect
with that return value, which is not what you want.