Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago

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

Log in to vote
0
Answered by 5 years ago

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

0
Oh, and replace player with LocalPlayer RunKittenzRComin 170 — 5y
0
ninja'd me EpicMetatableMoment 1444 — 5y
0
yea i just figured that out with the help of godlydeathdragon, tysm man for your help :) jetpush123 2 — 5y
0
np :D RunKittenzRComin 170 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

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")

0
Sadly I cant accept two answers but thank you very much, man. jetpush123 2 — 5y
0
Its alright! EpicMetatableMoment 1444 — 5y

Answer this question