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

How can you access a PlayerGui from a script inside of StarterPlayerScripts?

Asked by 6 years ago
Edited 6 years ago

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:

01local pow = game.Players.LocalPlayer.PlayerGui.PowerGui2.Frame -- the GUI
02local speed = pow.Select1 -- a text button
03if 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)  
16end
0
Try player:WaitForChild("PlayerGui") Thetacah 712 — 6y
0
for what line? Boi52893642864912 69 — 6y
0
local pow = game.Players.LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("PowerGui2"):WaitForChild("Frame") Thetacah 712 — 6y
0
Thanks Boi52893642864912 69 — 6y
0
mouse.KeyDown should not be used. Use UserInputService instead. Make sure that this is done in a local script. xPolarium 1388 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

I developed a solution based on Thetcah's comment and here's the answer:

01local pow = game.Players.LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("PowerGui2").Frame
02local speed = pow.Select1
03if 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)  
15end
0
mouse.KeyDown is deprecated. Use UserInputService instead. xPolarium 1388 — 6y
Ad

Answer this question