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

Why isn't player not a valid member of datamodel?

Asked by 5 years ago
Edited 5 years ago

Since I didn't want players to be able to spectate while they are in a match I created if statements; however, that isn't the problem. The problem is that in order to create the if statement clearer or easier I created variables.

Here is a script inside of the spectate gui:

gui = script.Parent.Button

local IsInMatch = game.player.IsInMatch.Value -- This is the variable which is recieveing the error message

if IsInMatch == true then
    gui.Visible = false
elseif IsInMatch == false then
    gui.Visible = true
end

Each player has a BoolValue (IsInMatch) and changes from false to true when the player is in a match or dies.

Here is my output window of the problem:

player is not a valid member of DataModel

Inside of every spawn is a function when the player touches the part and then it sets the value of IsInMatch to true or false.

I am confused by what this means. Please help me out! What is the problem? What do I have to change?

BTW I am new to scripting so thanks!

If you think the problem is something else, and let me know.

0
is this from the server or client User#23365 30 — 5y
0
It does not matter. He is trying to do game["Player"]. This is incorrect. @sbobl2345m, we need to see more of your script to figure out how to help you best. User#25115 0 — 5y
0
he could use LocalPlayer User#23365 30 — 5y

2 answers

Log in to vote
1
Answered by 5 years ago

If this is a local script...

local player = game.Players.LocalPlayer
local IsInMatch = player.IsInMatch.Value

If this is a server script, you have to find another way to get the player. Assuming you wrote the rest of the code in your game, there are already events set up which contain that. You can obtain the local player by using events like PlayerAdded of the Players service, MouseClick of ClickDetectors, and many more. Here's an example with PlayerAdded:

game.Players.PlayerAdded:Connect(function(player)
   print(player.Name)
end)
Ad
Log in to vote
0
Answered by 5 years ago

Player objects are parented under the Players service. You may have forgotten to insert the Players service inside of the path, causing an error.

Instead of writing...

local IsInMatch = game.player.IsInMatch.Value

Try writing...

local IsInMatch = game:GetService("Players").player.IsInMatch.Value

and see if the problem persists.

0
Players doesn't have a property or child "player" either (unless some player is really named "player"). aschepler 135 — 5y

Answer this question