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.
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.