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

KeyDown function enables GUI???????????

I'm trying to implement a menu in my game, and I'm having trouble. I can't see whats wrong. Any help would be appreciated, thank you.

function onKeyPress(inputObject, gameProcessedEvent)
	if inputObject.KeyCode == Enum.KeyCode.M then
		game.Player.LocalPlayer.PlayerGui.Menu.Enabled = true
	   end
end

game:GetService("UserInputService").InputBegan:connect(onKeyPress)

(This is inside StarterPlayer.StarterPlayerScripts, and is a LocalScript)

Error:

Script 'Players.jetpush123.PlayerScripts.LocalScript', Line 3
Player is not a valid member of DataModel

2 answers

✓ Accepted answer

Add a game.Players.player, not game.player. All players are stored in Players.

4 comments

0

Oh, and replace player with LocalPlayer

0

ninja'd me

0

yea i just figured that out with the help of godlydeathdragon, tysm man for your help :)

0

np :D

Error

Player is not a valid member of DataModel

Whats Wrong

I assume you're trying to index the Players service. You put Player but the players service is called Players

Solution

Change game.Player to game.Players or alternatively game:GetService("Players")

2 comments

0

Sadly I cant accept two answers but thank you very much, man.

0

Its alright!

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