Having an issue with a keybind script

The Problem
I am working on a key bind shop and I am having an issue with the HumanoidRootPart telling me it’s not a valid member of model.

The Script

The key bind works but the ‘E’ to text label (since I didn’t made it Image) is not showing because of the issue I am having.

Because of your crop, it is unclear what line the error is caused by, line 8 or line 21?

I am assuming the error is at line 21, I suppose the character did not properly load in yet when it’s trying to access the HumanoidRootPart.

Before line 19 (and before line 6), you should add some additional checks, whether the HumanoidRootPart (and the character) exists or not:

if not game.Players.LocalPlayer.Character then return end
if not game.Players.LocalPlayer.Character:FindFirstChild("HumanoidRootPart") then return end

If this still did not fix your issue, you should take a look if any other scripts perhaps mess with the HumanoidRootParts/Characters.

Try adding a WaitForChild() as the script is local and is probably loading before the humanoidrootpart has loaded. So it would be game.Players.LocalPlayer.Character:WaitForChild(“HumanoidRootPart”).Position

yes it’s 21. I just tested but if one of them is wrong shouldn’t I change both line 21 and 8?

Can you try adding the 2 lines of code I provided into both sections of your scripts? (line six and line nineteen) I think this might solve your problem.
If that did not work, you can also try @unwronged’s method of adding a WaitForChild.

You confused me a lot so I know I made it wrong but now the E is not even going to Visible = False

This is actually great debugging info. Now you know the script cannot find the Character/HumanoidRootPart. If you manually join your game, can you check yourself if there is any HumanoidRootPart in your character at all? Cause that might be the culprit here.

(Also, don’t forget to change the while true do on line 20 to while wait() do, this prevents a repeating loop that could crash your game.)

You know why it wasn’t showing me the E??
Because I forgot to make it Visible = true at the end… silly me :stuck_out_tongue: