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

How come it keeps saying "leaderstats is not a valid member of DataModel"?

Asked by 9 years ago

For some reason, when ever i try to make a GUI shop, it says, "leaderstats is not a valid member of DataModel". This is the script i used:

Cash = script.Parent.Parent.Parent.Parent.Parent.leaderstats.Points

function onClick()
    if Cash.Value >= 50 then
        Cash.Value = Cash.Value - 50
            local RockLaunch = game.Lighting.EconomyClassTicket:clone()
            RockLaunch.Parent = script.Parent.Parent.Parent.Parent.Parent.StarterGear
            local RockLaunch = game.Lighting.EconomyClassTicket:clone()
            RockLaunch.Parent = script.Parent.Parent.Parent.Parent.Parent.Backpack
            RockLaunch.Handle.Anchored = false
    end
end

script.Parent.MouseButton1Click:connect(onClick)

This is my leaderboard script:

game.Players.PlayerAdded:connect(function(player)
wait(.1)
local stats = Instance.new("IntValue")
stats.Name = "leaderstats"
stats.Value = 0
stats.Parent = player
local newStat = Instance.new("IntValue")
newStat.Name = "Credits"
newStat.Value = 50
newStat.Parent = stats
local newStat = Instance.new("BoolValue")
newStat.Name = "Tycoon"
newStat.Value = false
newStat.Parent = player
end)

2 answers

Log in to vote
1
Answered by 9 years ago

Well, you never made anything named 'Points' in leaderstats. I assume you mean credits?

Anyways, your problem is that leaderstats is not fully loaded when the code runs. Use WaitForChild().

Cash = script.Parent.Parent.Parent.Parent.Parent:WaitForChild("leaderstats"):WaitForChild("Credits")
Ad
Log in to vote
0
Answered by 3 years ago

you used credits in one script then cash in the other

Answer this question