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

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

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

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

you used credits in one script then cash in the other

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