Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to I make a database for linkedleaderboard kills only?

Asked by 6 years ago

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?

1 answer

Log in to vote
0
Answered by
OfcPedroo 396 Moderation Voter
6 years ago
Edited 6 years ago

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)
0
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 WTFITSAHACKER -5 — 6y
0
ok, i edited the script! Try again. OfcPedroo 396 — 6y
0
done! should be working. OfcPedroo 396 — 6y
0
How do I put 2 leaderboard at one games? like 2 different types of leaderboard one for "cash" one for "deaths" WTFITSAHACKER -5 — 6y
View all comments (12 more)
0
I'll make that for you! OfcPedroo 396 — 6y
0
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)! OfcPedroo 396 — 6y
0
I want it save kills only,I don't need cash and deaths to be saved. WTFITSAHACKER -5 — 6y
0
ok, so................. you only want it to create kills leaderstat and save it everytime a player leaves the game? OfcPedroo 396 — 6y
0
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 WTFITSAHACKER -5 — 6y
0
kinda strange, but ok. ill edit the script, hold on a sec. OfcPedroo 396 — 6y
0
done, should be working. Only stores and saves kills leaderstat rn. Enjoy, and if it works, please mark as the answer! ;) OfcPedroo 396 — 6y
0
Alright WTFITSAHACKER -5 — 6y
0
Can you accept my roblox friend request so I can explain it clearly on roblox studio team create? WTFITSAHACKER -5 — 6y
0
alright! OfcPedroo 396 — 6y
0
ya.. but don't say that on sc dood, only on rblx OfcPedroo 396 — 6y
0
Hey check roblox,I need some helps WTFITSAHACKER -5 — 6y
Ad

Answer this question