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 5 years ago
Edited 5 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:

local pow = game.Players.LocalPlayer.PlayerGui.PowerGui2.Frame -- the GUI
local speed = pow.Select1 -- a text button
if speed.Text == "Selected" then
       -- v all the key press stuff v --
    m.KeyDown:Connect(function(k)
        if k == "q" then
            if db == true then
        game.Players.LocalPlayer.Character:FindFirstChild("Humanoid").WalkSpeed = 40
                db = false
                wait(10)
                db = true
        game.Players.LocalPlayer.Character:FindFirstChild("Humanoid").WalkSpeed = 16
            end
        end
    end)   
end
0
Try player:WaitForChild("PlayerGui") Thetacah 712 — 5y
0
for what line? Boi52893642864912 69 — 5y
0
local pow = game.Players.LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("PowerGui2"):WaitForChild("Frame") Thetacah 712 — 5y
0
Thanks Boi52893642864912 69 — 5y
0
mouse.KeyDown should not be used. Use UserInputService instead. Make sure that this is done in a local script. xPolarium 1388 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

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

local pow = game.Players.LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("PowerGui2").Frame
local speed = pow.Select1
if speed.Text == "Selected" then
    m.KeyDown:Connect(function(k)
        if k == "q" then
            if db == true then
                game.Players.LocalPlayer.Character:FindFirstChild("Humanoid").WalkSpeed = 40
                db = false
                wait(10)
                db = true
                game.Players.LocalPlayer.Character:FindFirstChild("Humanoid").WalkSpeed = 16
            end
        end
    end)   
end
0
mouse.KeyDown is deprecated. Use UserInputService instead. xPolarium 1388 — 5y
Ad

Answer this question