Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

My GUI won't work?

I wrote the code for a GUI and it worked flawlessly in Studio but not in Test/Play mode.

I figured out the problem is the first bit of code: local p = game.Players.Player1.PlayerGui.ScreenGui.PlayerLoadout

But I don't know how to make it accessible to all players instead of just Player1. Help?

2 answers

Assuming this is in a LocalScript, the LocalPlayer property of Players will work for you:

local p = game.Players.LocalPlayer.PlayerGui.ScreenGui.PlayerLoadout

Otherwise, you'll have to use the PlayerAdded event to make this run for each any every Player:

game.Players.PlayerAdded:connect(function(player)
	local p = player.PlayerGui:WaitForChild("ScreenGui"):WaitForChild("PlayerLoadout")
end)

2 comments

0

Neither of the above methods work. I'm getting:Players.Player.PlayerGui.ScreenGui.MainMenu.Loadout.Loadout:7: attempt to index global 'p' (a nil value)

0

Sorry for the delayed response. What is the exact error you're getting? (You should be using game.Players.LocalPlayer, not game.Players.Player))

game.Players.PlayerAdded:connect(function(player) local p = player.PlayerGui:WaitForChild("ScreenGui"):WaitForChild("PlayerLoadout") end) 

local p = game.Players.LocalPlayer.PlayerGui.ScreenGui.PlayerLoadout

function onButtonClicked()

script.Parent.Parent:TweenPosition(UDim2.new(0.025, 0 , 1, 0))
wait(0.5)
p.Visible = true
wait(0.2)
p:TweenPosition(UDim2.new(0, 0, 0.84, 0))	
	

end


script.Parent.MouseButton1Click:connect(onButtonClicked)	

This discussion is preserved as it was. New answers, comments, and votes are closed.