I am trying to bind keybinds for certain actions
this script works completely fine without the addition of PlayerGui
i dont know what causes it but the script never gets the PlayerGui and it doesnt give a warn with infinite yield possible on WaitForChild
You cant do the other action when the line
local PlayerGui = player:WaitForChild("PlayerGui")
exists
basically the script completely stops when it tries to get the PlayerGui.
local Uis = game:GetService("UserInputService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local PlayerGui = player:WaitForChild("PlayerGui")
local InventoryGui = PlayerGui.InventoryGui
player.CharacterAdded:Connect(function(character)
local humanoid:Humanoid = character:WaitForChild("Humanoid")
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://118410660664793"
animation.Name = "ProneAnim"
animation.Parent = humanoid
local ProneAnimationTrack = humanoid.Animator:LoadAnimation(animation)
ProneAnimationTrack.Looped = true
local e1
e1 = Uis.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed then return end
if input.KeyCode == Enum.KeyCode.LeftControl then
if not ProneAnimationTrack.IsPlaying then
ProneAnimationTrack:Play()
if humanoid then
humanoid.WalkSpeed = 5
end
else
ProneAnimationTrack:Stop()
if humanoid then
humanoid.WalkSpeed = 16
end
end
elseif input.KeyCode == Enum.KeyCode.Tab then
InventoryGui.Enabled = not InventoryGui.Enabled
end
end)
local e2
e2 = humanoid.Died:Connect(function()
e1:Disconnect()
e2:Disconnect()
end)
end)
local StarterGui = game:GetService("StarterGui")
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList,false)
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,false)
PlayerGui is clearly a child of the Player, there’s nothing stopping you from using WaitForChild.
That aside, this issue seems quite weird, as when I try to recreate this it definetely returns the PlayerGui.
Perhaps you could try using a BindableEvent to tell a script under the InventoryGui to close itself instead.
Other issue: You don’t run the CharacterAdded function if the character is already added before loading the script, which tends to happen quite a lot. You should run the CharacterAdded function before starting the :Connect once.
I’ve tested this further and it appears your right, WaitForChild() does work. In the tests I did at the time of commenting, it didn’t, which is strange. Doing this again the exact opposite occured, the . operator didn’t work, as opposed to :WaitForChild which did.