Wins is not a valid member of IntValue

You can write your topic however you want, but you need to answer these questions:
1.Basically i’m trying to add a cash stat alongside a win stat that already exists but when i try it gives me the error
“Wins is not a valid member of IntValue”
line 712
Here’s the code for the win script
https://cdn.discordapp.com/attachments/699014109491888198/722107446667247648/message.txt

print("Cash Leaderboard Loaded")


function onPlayerEntered(newPlayer)

	local stats = Instance.new("IntValue")
	stats.Name = "leaderstats"		--=]Dont Touch This[=--

	local cash = Instance.new("IntValue")
	cash.Name = "Cash"       --=]name of currency[=--
	cash.Value = 25      --=]starting money[=--

	cash.Parent = stats
	stats.Parent = newPlayer	--=]Dont Touch This[=--
end



game.Players.ChildAdded:connect(onPlayerEntered)

Cash script

1 Like

Can you provide the win script in a code block?

You never set stats.Parent to anything so it is just an Instance floating around in nil.
Also, use

game.Players.PlayerAdded:Connect(function(player)
    -- Do Stuff
end)

it’s too big lol i already tried

The link for the win script doesn’t work for me.

So i attempted a fix but now I have a new problem; only the cash stat shows up. I tried putting the stuff in the same script. https://cdn.discordapp.com/attachments/699014109491888198/722109031065583646/SPOILER_message.txt

Uhh
game.Players.PlayerAdded:connect(function(player)
local q = Instance.new(“IntValue”)
q.Name = “Queue”
q.Parent = player
script.Stats:Clone().Parent = player

	local leaderstats = Instance.new("BoolValue")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	local ex = Instance.new("IntValue")
	ex.Name = "Wins"
	ex.Value = ps:GetAsync(player.UserId) or 0
	ps:SetAsync(player.UserId, ex.Value)
	ex.Changed:connect(function()
		ps:SetAsync(player.UserId, ex.Value)
		
	ex.Name = "Cash"
	ex.Value = ps:GetAsync(player.UserId) or 0
	cs:SetAsync(player.UserId, ex.Value)
	ex.Changed:connect(function()
		cs:SetAsync(player.UserId, ex.Value)
		
	end)
	ex.Parent = leaderstats
end)

I have no idea what’s going on but there are only two values you are creating:
Cash & Leaderstats

I’m not smart it’s supposed to make wins and Cash stats and i’m new to scripting so I don’t quite know how to do both

1 Like

So if you’re new to scripting, where did the 800 line script come from?

my friend assisted me with it a while ago

https://education.roblox.com/en-us/resources/adventure-game-creating-a-leaderboard
Redo it. There are a lot of mistakes in there and a lot of deprecation.

That’s what I looked at to set it up ;-;

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("BoolValue")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local wins = Instance.new("IntValue")
	wins.Name = "Wins"
	wins.Value = -- Get The Value
	wins.Parent = leaderstats
	
	wins:GetPropertyChangedSignal("Value"):Connect(function()
		-- Set the value
	end)
	
	local cash = Instance.new("IntValue")
	cash.Name = "Cash"
	cash.Value = -- Get The Value
	cash.Parent = leaderstats
	
	cash:GetPropertyChangedSignal("Value"):Connect(function()
		-- Set the value
	end)
end)

Just replace my comments with the data store values.

So that kinda broke the game because I forgot to mention theres a leaderboard

local CashODS = game:GetService("DataStoreService"):GetOrderedDataStore("WinStoreSystem")
 
local function Handler()
    local Success, Err = pcall(function()
        local Data = CashODS:GetSortedAsync(false, 12)
        local CashPage = Data:GetCurrentPage()
        for Rank, Data in ipairs(CashPage) do
            local Name = Data.key
            local Cash = Data.value
            local NewObj = game.ReplicatedStorage:WaitForChild("lbFrame1"):Clone()
            NewObj.Player.Text = Name
            NewObj.Cash.Text = Cash
            NewObj.Rank.Text = "#"..Rank
            NewObj.Position = UDim2.new(0, 0, NewObj.Position.Y.Scale + (0.08 * #game.Workspace.Lobby.GlobalLeaderboard1.lbGUI1.Holder1:GetChildren()), 0)
            NewObj.Parent = game.Workspace.Lobby.GlobalLeaderboard1.lbGUI1.Holder1
        end
    end)
    if not Success then
        error(Err)
    end
end
 
while true do
    for _,Player in pairs(game.Players:GetPlayers()) do
        CashODS:SetAsync(Player.Name, Player.leaderstats.Wins.Value)
    end
    for _,v in pairs(game.Workspace.Lobby.GlobalLeaderboard1.lbGUI1.Holder1:GetChildren()) do
        if v.Name == "lbFrame1" then
            v:Destroy()
        end
    end
    Handler()
    wait(10)
end

You don’t need a

wins:GetPropertyChangedSignal("Value"):Connect(function()

or

cash:GetPropertyChangedSignal("Value"):Connect(function()

Since you’ll be changing these values from a serverscript, they’ll automatically update. Even if you change these values from a seperate serverscript, it’ll still recognize any changes. You would only need this if you changed leaderstat values from a LocalScript (don’t see why you would), but even with that, you would most likely use a remote event.

This is for setting values to the Data Store not for updating values. I don’t agree it should be done this way but this is the way he wants it done.

Ah, I didn’t see that before. I would just SetAsync for the value only when the player leaves, but yeah that works too.

i still am very confused help my tiny brain

For a DataStore, you first need to call for DataStoreService, and you need to make a datastore name for each value.

local ds = game:GetService("DataStoreService")
local cashstore = ds:GetDataStore("Cash")
local winstore = ds:GetDataStore("Wins")

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder",player)
	leaderstats.Name = "leaderstats"
	
	local wins = Instance.new("IntValue",leaderstats)
	wins.Name = "Wins"
	wins.Value = 0 --Value will only be 0 if it is a new player or they are actually at 0
	
	local cash = Instance.new("IntValue",leaderstats)
	cash.Name = "Cash"
	cash.Value = 0

    local CashData
    local WinData
	
	local success, errormessage = pcall(function()
		CashData = cashstore:GetAsync(Player.userId.."-Cash")
		WinData = winstore:GetAsync(Player.userId.."-Wins")
	end)
	
	if success then
		cash.Value = CashData --Sets Value
		wins.Value = WinData
	else
		print("There was an error while getting data.")
		warn(errormessage)
	end
end)

--Then when the player leaves, you SetAsync for their current values

game.Players.PlayerRemoving:Connect(function(player)
	local success, errormessage = pcall(function()
		cashstore:SetAsync(player.userId.."-Cash", player.leaderstats:FindFirstChild("Cash").Value)
		winstore:SetAsync(player.userId.."-Wins", player.leaderstats:FindFirstChild("Wins").Value)
	end)
	
	if success then
		print("Data was successfully stored!")
	else
		print("There was an error while storing data.")
		warn(errormessage)
	end
end)