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?
✓ ANSWER ACCEPTED
How to I make a database for linkedleaderboard kills only?
1 answer
✓ Accepted answer
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)
This discussion is preserved as it was. New answers, comments, and votes are closed.

16 comments
I'm trying to add the datastore (Kills only) to my tycoon,but when I add a datastore it screw up the cash and deaths
ok, i edited the script! Try again.
done! should be working.
How do I put 2 leaderboard at one games? like 2 different types of leaderboard one for "cash" one for "deaths"
I'll make that for you!
Alright, it now holds and saves 2 leaderstats, cash and deaths. This gave a lot of work, so please, mark as the answer if it works (and it should work)!
I want it save kills only,I don't need cash and deaths to be saved.
ok, so................. you only want it to create kills leaderstat and save it everytime a player leaves the game?
Yes because I wanna add a competitive leaderboard for my tycoon and "kills" only but everytime i add a database that save kills it screw up my tycoon linkedleaderboard
kinda strange, but ok. ill edit the script, hold on a sec.
done, should be working. Only stores and saves kills leaderstat rn. Enjoy, and if it works, please mark as the answer! ;)
Alright
Can you accept my roblox friend request so I can explain it clearly on roblox studio team create?
alright!
ya.. but don't say that on sc dood, only on rblx
Hey check roblox,I need some helps