I have A datastore which holds leaderstats but seems to be creating multiple values and assigning them to every player. The part is only A way to give value for the data store to use I do not need to optimise that I just need to know how to make values for each player. Here is the game:

[]http://www.roblox.com/games/5215699464/Nudos-Noodle-House-Alpha?refPageId=a9a19ee3-408e-4d48-a5b7-be7079b8c565 ) Do not dislike just because the game is new this is meant to help. Here is the dev forum thread:

(http://devforum.roblox.com/t/not-solved-how-to-only-create-one-int-value-per-player-and-have-the-value-attached-to-them/644027/3)

-- Datastore script
local DSS = game:GetService("DataStoreService")
 
local cashData = DSS:GetDataStore("cashDataStore")
 
game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		
    	local leaderstats = Instance.new("Folder")
		leaderstats.Name = "leaderstats"
		leaderstats.Parent = Player
		
    	local Cash = Instance.new("IntValue")
		Cash.Name = "Cash"
    	Cash.Parent = leaderstats
    	Cash.Value = cashData:GetAsync(Player.userId) or 0
 
		game.Players.PlayerRemoving:connect(function(Player)
			cashData:SetAsync(Player.userId, Cash.Value)
		end)


		while true do
			wait(60)
			pcall(function()
			cashData:SetAsync(Player.userId, Cash.Value)	
			end)
		end
	end)
end)
game.Players.PlayerRemoving:Connect(function()
	
end)

Part script

local brick = script.Parent

function onTouched(hit)
    for i,player in ipairs(game.Players:GetPlayers()) do
        if player.Character then
            local stat = player:FindFirstChild("leaderstats")
			            if stat then
                player.leaderstats.Cash.Value = player.leaderstats.Cash.Value +1
            end
        end
    end
end


brick.Touched:connect(onTouched)

3 comments

0

Could someone make the link work by posting it in comments I am unaware of how to do it: https://devforum.roblox.com/t/not-solved-how-to-only-create-one-int-value-per-player-and-have-the-value-attached-to-them/644027

0

Combined with dev forum 140 people have viewed this. And no one knows the solou tion