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

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

Asked by 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.

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

You forgot to do .LocalPlayer

To correctly reference the player in a LocalScript use game.Players.LocalPlayer. Also don't use .Value in a variable. I've also added .Changed to this so that its called anytime the value changes, otherwise this will only run one time.

local gui = script.Parent.Button

local IsInMatch = game.Players.LocalPlayer.IsInMatch -- This is the variable which is recieveing the error message

IsInMatch.Changed:Connect(function()
    if IsInMatch.Value == true then
        gui.Visible = false
    else
        gui.Visible = true
    end
end)
0
use local Varible = ... not Variable = ... (line 01) yHasteeD 1819 — 5y
0
Good catch, its leftover code from his original script i forgot to fix. DinozCreates 1070 — 5y
Ad

Answer this question