I am trying to make a key press event, and it relies on a GUI in the PlayerGui, but when I try it says "PlayerGui is not a valid member of Player" here is my script:
01 | local pow = game.Players.LocalPlayer.PlayerGui.PowerGui 2. Frame -- the GUI |
02 | local speed = pow.Select 1 -- a text button |
03 | if speed.Text = = "Selected" then |
04 | -- v all the key press stuff v -- |
05 | m.KeyDown:Connect( function (k) |
06 | if k = = "q" then |
07 | if db = = true then |
08 | game.Players.LocalPlayer.Character:FindFirstChild( "Humanoid" ).WalkSpeed = 40 |
09 | db = false |
10 | wait( 10 ) |
11 | db = true |
12 | game.Players.LocalPlayer.Character:FindFirstChild( "Humanoid" ).WalkSpeed = 16 |
13 | end |
14 | end |
15 | end ) |
16 | end |
I developed a solution based on Thetcah's comment and here's the answer:
01 | local pow = game.Players.LocalPlayer:WaitForChild( "PlayerGui" ):WaitForChild( "PowerGui2" ).Frame |
02 | local speed = pow.Select 1 |
03 | if speed.Text = = "Selected" then |
04 | m.KeyDown:Connect( function (k) |
05 | if k = = "q" then |
06 | if db = = true then |
07 | game.Players.LocalPlayer.Character:FindFirstChild( "Humanoid" ).WalkSpeed = 40 |
08 | db = false |
09 | wait( 10 ) |
10 | db = true |
11 | game.Players.LocalPlayer.Character:FindFirstChild( "Humanoid" ).WalkSpeed = 16 |
12 | end |
13 | end |
14 | end ) |
15 | end |