generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: leaderstats issues

Previous Thread :: Next Thread 
spinywind is online. spinywind
Joined: 26 Jan 2012
Total Posts: 3580
01 Feb 2016 01:53 PM
so 128gigabyte mostly made this and it gives xp, kills, deaths and cash when a player dies. How would i make it so when u get a kill, you earn the xp, cash and kill and when u die you get one death.



local leaderboardData = game:getService("DataStoreService"):getDataStore("leaderboard")
local leaderboard = {

{"Int"; "Kills:"; function(player, data)
return (data["Kills:"]);
end;};

{"Int"; "Deaths:"; function(player, data)
return (data["Deaths:"]);
end;};

{"Number"; "Cash:"; function(player, data)
return (data["Cash:"]);
end;};

{"Int"; "Level"; function(player, data)
return (data.Level);
end;};

{"Number"; "XP"; function(player, data)
return (data["XP"]);
end;};
}

local function newCharacter(character)
character:waitForChild("Humanoid").died:wait()
local player = game.Players:getPlayerFromCharacter(character)
player.leaderstats["Deaths:"].Value = (player.leaderstats["Deaths:"].Value + 1)
local creator = character.Humanoid:findFirstChild("creator")
if (creator and creator:isA("ObjectValue") and creator.Value and creator.Value:isA("Player")) then
creator.Value:waitForChild("leaderstats"):waitForChild("Kills:").Value = (creator.Value.leaderstats["Kills:"].Value + 1)
creator.Value:waitForChild("leaderstats"):waitForChild("XP").Value = (creator.Value.leaderstats.XP.Value + 3)
creator.Value:waitForChild("leaderstats"):waitForChild("Cash:").Value = (creator.Value.leaderstats["Cash:"].Value + 100)
if player.leaderstats.Level.Value == 55 then
player.leaderstats.Level.Value = player.leaderstats.Level.Value + 0
player.leaderstats.XP.Value = 0


elseif player.leaderstats.XP.Value>=player.leaderstats.Level.Value then
player.leaderstats.Level.Value = player.leaderstats.Level.Value + 1
player.leaderstats.XP.Value = 0
player.leaderstats.XP.Value = player.leaderstats.XP.Value * 4
end
end
end

game.Players.playerAdded:connect(function(player)
local leaderstats, data = Instance.new("Folder", nil), nil --[[Its a bad idea to parent the leaderstats to the player before putting the actual stats in it.]]
leaderstats.Name = "leaderstats"
leaderboardData:updateAsync(("userId" .. tostring(player.UserId)), function(value) --[[Save via the userId rather than name in case they chang their username.]]
data = (value or {
["Kills:"] = 0;
["Kills:"] = 0;
["Cash:"] = 0;
["Level"] = 0;
["XP"] = 0;
})
return (data)
end)
for _, stat in next, (leaderboard) do
local leaderstat = Instance.new((stat[1] .. "Value"), leaderstats)
leaderstat.Name, leaderstat.Value = stat[2], stat[3](player, data)
end
leaderstats.Parent = player;

if (player.Character) then
newCharacter(player.Character)
end
player.characterAdded:connect(newCharacter)
end)

game.Players.playerRemoving:connect(function(player)
leaderboardData:updateAsync(("userId" .. tostring(player.userId)), function(value)
for stat, _ in next, (value) do
value[stat] = player.leaderstats[stat].Value
end
return (value);
end)
end)


Report Abuse
85db is not online. 85db
Joined: 22 Jan 2011
Total Posts: 254
01 Feb 2016 01:55 PM
Lol. Learn how to script or get some robux?


~CrayBray
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image