After I added the datastore to my game,it screw up the linkedleaderboard and make the deaths and cash to "-". How do I make a database for linkedleaderboard kills only?
Try the following in a regular script:
Oh yeah, by the way, make sure the leaderstat you want to save is called "linkedleaderboard kills", because that's what I placed in the script. if it's not, please change the leaderstats name. You also need to delete your script to create the leaderstats, and the one that you're trying to use, to save the leaderstats: This script makes both! :D
function DataHandler(p,o,key) -- DataHandler(Player, Object [, Key]) local types = { IntValue = "Number"; NumberValue = "Number"; ObjectValue = "Instance"; BoolValue = "Boolean"; StringValue= "String"; } local t = types[o.ClassName] if (not t) then return end key = (type(key) == "string" and key or o.Name) -- If it's a string, keep it the same, ELSE change it to the object's name. Allows 'key' to be an optional argument. key = (#key > 0 and key or key.Name == o.Name and o.ClassName or o.Name) -- If length of string is greater than 0, keep it the same if (not p.DataReady) then -- ELSE if it is equal to the object's name then that means that the p:WaitForDataReady() -- object's name is blank, therefore make 'key' the ClassName. end -- ELSE make it the name of the object. local Save,Load = p[("Save%s"):format(t)],p[("Load%s"):format(t)] -- Steal the load and save functions from the player o.Value = Load(p,key) -- The same as p:LoadTYPE(key). Since it's no longer a method, the player must be the first argument local lastV = o.Value o.Changed:connect(function(v) lastV = v delay(1,function() -- Give a 1 second buffer to see if the value changes anymore. If so, stop the operation. If it goes 1 second without changing, it will automatically save. if (lastV ~= v) then return end -- This way you don't save a value 20 times in 1 second if it changes constantly. Lower data processing = less lag Save(p,key,v) end) end) end --A table for holding all the player's leaderstat values local playerLeaderstats = {} game.Players.PlayerAdded:connect(function(player) playerLeaderstats[player] = {} playerLeaderstats[player]["Kills"] = 0 local leaderstats = Instance.new("Model") leaderstats.Name = "leaderstats" leaderstats.Parent = player local kills= Instance.new("IntValue") kills.Name = "Kills" kills.Value = playerLeaderstats[player]["Kills"] kills.Parent = leaderstats DataHandler(player,kills,"Kills") end)