Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

My GUI won't work?

Asked by 9 years ago

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

Log in to vote
2
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

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)
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) shadownova62 5 — 9y
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)) adark 5487 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your answer.
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)    

Answer this question