You can write your topic however you want, but you need to answer these questions:
What do you want to achieve?
i want to create a variable for a viewportframe inside of a gui inside of the playergui with a local script
What is the issue? Include screenshots / videos if possible!
it only works cause i typed my username in
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
i looked on the dev hub but it all uses functions instead
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
part of the script
local players = game:GetService("Players")
local playergui = players:WaitForChild("ALEXS12345678910").PlayerGui.MainMenuGUI.MainMenu.SkinsAndGearFrame.MainViewportFrame
local viewport = playergui
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.
local players = game:GetService("Players")
local selfCharacter = workspace:FindFirstChild("ALEXS12345678910")
if selfCharacter then
local selfPlayer = players:GetPlayerFromCharacter(selfCharacter)
if selfPlayer then
local selfPlrGui = selfPlayer:FindFirstChild("PlayerGui")
if selfPlrGui then
local selfGuiObject = selfPlrGui.MainMenuGUI.MainMenu.SkinsAndGearFrame.MainViewportFrame
end
end
end
Do you want this to only work for you or all players? As the above post suggested this should be handled from the client using a local script, you can reference the ViewportFrame & BasePart instance correctly from a local script, the script doesn’t have to be parented to either.
local players = game:GetService("Players")
local playergui
local viewport
players.PlayerAdded:Connect(function(plr)
if plr.Name == "your name here" then
playergui = plr:WaitForChild("PlayerGui"):WaitForChild("MainMenuGUI").MainMenu.SkinsAndGearFrame.MainViewportFrame
viewport = playergui
end
end)
I’m not entirely sure what you wanted, though. Could you please elaborate a bit more?
Fewer lines of code. Also, it uses an Index instead of a variable, which is better, because instead of referencing a player object, it literally gets the player object.