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

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

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

5 comments

0

Try player:WaitForChild("PlayerGui")

0

for what line?

0

local pow = game.Players.LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("PowerGui2"):WaitForChild("Frame")

0

Thanks

0

mouse.KeyDown should not be used. Use UserInputService instead. Make sure that this is done in a local script.

1 answer

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

1 comment

0

mouse.KeyDown is deprecated. Use UserInputService instead.

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