BackgroundColor3 doesn't work in scripts

I am learning to script, so this might be a really dumb question for some people but for some reason this script doesnt work. See at bottom

 local plr = game.Players.LocalPlayer	
 
 local frame = Instance.new("Frame")
 
 frame.Size = UDim2.new(1,0,1,0)
 
 frame.BackgroundColor3 = Color3.new(BackgroundColor3)
 
 wait(1)
 
 frame.Parent = plr.PlayerGui.ScreenGui
 
 return gui
end

local returngui = gui(255,255,0)

print("color changing")

wait(2)

returngui.BackgroundColor3 = Color3.new(255,0,255) 

– There is an error saying
“Players.KingJoseon.PlayerGui.LocalScript:21: attempt to index function with ‘BackgroundColor3’” which is the last line

So first, you have return which should be located in function which you obiusly don’t have in this script.
What local returngui = gui(255,255,0) represents, I mean gui(255,255,0) ?
So basicly that “returngui” which you are trying to set BackgroundColor3 don’t have that property because it isn’t correctly declared. You made mistake in script.

I do, it didnt show there for some reason.
(https://gyazo.com/7065bbd76f2944585ef1104d0819183b.png)
https://gyazo.com/7065bbd76f2944585ef1104d0819183b Theres still an error.

Here is the script that works, you need tu return frame which you created, so after you can use it as reference to created frame.

function gui(BackgroundColor3)
local plr = game.Players.LocalPlayer	
 
 local frame = Instance.new("Frame")
 
 frame.Size = UDim2.new(1,0,1,0)
 
 frame.BackgroundColor3 = Color3.new(BackgroundColor3)
 
 wait(1)
 
 frame.Parent = plr.PlayerGui.ScreenGui
 
 return frame -- returning frame insted of ...  gui ?
end

local returngui = gui(255,255,0) -- storing frame that you created in this variable so it can be accesed later

print("color changing")

wait(2)

returngui.BackgroundColor3 = Color3.new(255,0,255) -- accesing frame that you have created in function.

Thanks, I didnt realise that. Appreicated/

1 Like