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 » Scripting Helpers
Home Search
 

Data Persistance LEADERBOARD HELP PLZ!!

Previous Thread :: Next Thread 
robotmega is not online. robotmega
Joined: 16 May 2009
Total Posts: 14084
18 Jul 2011 04:29 PM
function onXPChanged(player, XP, level)
if XP.Value>=level.Value * 10 then
XP.Value = XP.Value - level.Value * 10
level.Value = level.Value + 1
end
end

function onLevelUp(player, XP, level)
if player.Character~=nil then
for i = 1,5 do
local fireworks = Instance.new("Part")
fireworks.Shape = 0
fireworks.formFactor = "Symmetric"
fireworks.Size = Vector3.new(1,1,1)
fireworks.BrickColor = BrickColor.Random()
fireworks.CFrame = player.Character.Head.CFrame + Vector3.new(0,2,0)
fireworks.Parent = game.Workspace
game:GetService("Debris"):AddItem(fireworks, 2)
fireworks.Velocity = Vector3.new(math.random(-30,30),math.random(-30,30),math.random(-30,30))
end
end
local m = Instance.new("Hint")
m.Parent = game.Workspace
m.Text = player.Name .. " has leveled up!"
wait(3)
m.Parent = nil
end

function onPlayerRespawned(player)
wait(5)
player.Character.Humanoid.Health = player.leaderstats.Level * 999
player.Character.Humanoid.MaxHealth = player.leaderstats.Level * 1000
--[[
local stuff = player.Backpack:GetChildren()
wait(5)
for i = 1,#stuff do
local name = stuff[i].Name
if game.Starterpack:findFirstChild(name)==nil then
stuff[i]:Clone().Parent = player.Backpack
end
end
--]]
end


function saveScore(player, score)
player:SaveNumber("Level", score)
end

function saveScore2(player, score)
player:SaveNumber("XP", score)
end

function saveScore3(player, score)
player:SaveNumber("Cash", score)
end


function loadScore(player, level)
local score = player:LoadNumber("Level")

if score ~= 1 then
level.Value = score
else
print("Nothing to load/score was 0")
end

end

function loadScore2(player, xp)
local score = player:LoadNumber("XP")

if score ~= 0 then
xp.Value = score
else
print("Nothing to load/score was 0")
end

end

function loadScore3(player, c)
local score = player:LoadNumber("Cash")

if score ~= 10 then
c.Value = score
else
print("Nothing to load/score was 0")
end

end

function onPlayerEntered(newPlayer)
local stats = Instance.new("IntValue")
stats.Name = "stats"

local xp = Instance.new("IntValue")
xp.Name = "XP"
xp.Value = 0

local level = Instance.new("IntValue")
level.Name = "Level"
level.Value = 5

local c = Instance.new("IntValue")
c.Name = "Cash"
c.Value = 15

local t = Instance.new("IntValue")
t.Name = "Type"
t.Value = 0

local t2 = Instance.new("IntValue")
t2.Name = "Type2"
t2.Value = 0

local p = Instance.new("IntValue")
p.Name = "Potion"
p.Value = 3

local ts = Instance.new("IntValue")
ts.Name = "ThunderStone"
ts.Value = 0

local w = Instance.new("IntValue")
w.Name = "WaterStone"
w.Value = 0

local f = Instance.new("IntValue")
f.Name = "FireStone"
f.Value = 0

local r = Instance.new("IntValue")
r.Name = "Friendship"
r.Value = 10

xp.Parent = stats
level.Parent = stats
c.Parent = stats
t.Parent = stats
t2.Parent = stats
p.Parent = stats
ts.Parent = stats
w.Parent = stats
f.Parent = stats
r.Parent = stats

stats.Parent = newPlayer

xp.Changed:connect(function() onXPChanged(newPlayer, xp, level) end)
level.Changed:connect(function() onLevelUp(newPlayer, xp, level) end)

newPlayer:WaitForDataReady() -- IMPORTANT: after player.DataReady = true, it won't become false again. You need DataReady to be true for a player before you can load or save data.

-- try loading the player's score
loadScore(newPlayer, clicks)
loadScore2(newPlayer, clicks2)
loadScore3(newPlayer, clicks3)


newPlayer.Changed:connect(function (property)
if (property == "Character") then
onPlayerRespawned(newPlayer)
end
end)
end

function onPlayerRemoving(player)
print("Attempting to save score for " .. player.Name)
local stats = player:FindFirstChild("leaderstats")
if (stats ~= nil) then
local clicks = stats:FindFirstChild("Level")
local clicks2 = stats:FindFirstChild("XP")
local clicks3 = stats:FindFirstChild("Cash")
if (clicks ~= nil)and(clicks2 ~= nil)and(clicks3 ~= nil) then
saveScore(player, clicks.Value)
saveScore2(player, clicks2.Value)
saveScore3(player, clicks3.Value)
end
end
end

game.Players.ChildAdded:connect(onPlayerEntered)
game.Players.PlayerRemoving:connect(onPlayerRemoving)

When i test the script, it doesnt saves but leaderboard works!
Any help? D:
Report Abuse
RobotWallE is not online. RobotWallE
Joined: 17 Jan 2009
Total Posts: 498
18 Jul 2011 05:16 PM
Posting 100 lines and asking for help won't get you anywhere. Posting 100 lines and telling us where the problem is might.~MrDoomBringer.
Report Abuse
robotmega is not online. robotmega
Joined: 16 May 2009
Total Posts: 14084
18 Jul 2011 08:36 PM
Posts that doesnt help, Poster wasting his time.
~Your Grandma
Report Abuse
alexmach1 is not online. alexmach1
Joined: 02 May 2008
Total Posts: 1977
18 Jul 2011 08:36 PM
tl;dr. learn2output.
Report Abuse
robotmega is not online. robotmega
Joined: 16 May 2009
Total Posts: 14084
19 Jul 2011 12:43 PM
Learn to read.
At the final of the script i said "The script works but it doesnt saves".
~Your Grandpa
Report Abuse
SarahAngel is not online. SarahAngel
Joined: 12 Dec 2009
Total Posts: 2166
19 Jul 2011 12:55 PM
@Robot, that doesn't tell us anything really. >.>
Report Abuse
robotmega is not online. robotmega
Joined: 16 May 2009
Total Posts: 14084
19 Jul 2011 02:42 PM
@Sarah
Posts that doesnt help, Poster wasting his time.
~Your Grandma
Umad? o3o
Report Abuse
alexmach1 is not online. alexmach1
Joined: 02 May 2008
Total Posts: 1977
19 Jul 2011 09:02 PM
i cant help you if you do not define the problem -_-
http://www.roblox.com/Forum/ShowPost.aspx?PostID=9772680
Report Abuse
me2kool2talk2u is not online. me2kool2talk2u
Joined: 19 Feb 2007
Total Posts: 2914
19 Jul 2011 09:03 PM
I knew this was for an RPG :D
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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