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: While true do EXP function isn't working...

Previous Thread :: Next Thread 
EvolutionPower is not online. EvolutionPower
Joined: 16 Dec 2013
Total Posts: 873
17 Sep 2016 05:37 AM
PS: Sorry about the same post but i wanted it to be clean. ----- Hi, i am wondering if anyone can change this script so that it gives like 30 exp per 6 seconds. I have thought of this so far:
while true do
wait(6)
game.Players.LocalPlayer.XP.Value = game.Players.LocalPlayer.XP.Value + 30
end

^^^That was put at the bottom part with the lvling up part but it didn't work, i mean it did give 30 EXP per 6 seconds but didn't lvl up, please help!



local leader = Instance.new("Folder")
leader.Name = "leaderstats"
leader.Parent = player
local levelz = Instance.new("IntValue")
levelz.Value = level:GetAsync(tostring(player.userId)) or 1
levelz.Name = "Level"
levelz.Parent = player:WaitForChild("leaderstats")
local xpz = Instance.new("NumberValue")
xpz.Value = XP:GetAsync(tostring(player.userId))
xpz.Name = "XP"
xpz.Parent = player
local xpn = Instance.new("IntValue")
xpn.Value = AXP:GetAsync(tostring(player.userId)) or 500
xpn.Name = "XPNeeded"
xpn.Parent = player
xpz.Changed:connect(function()
if player:WaitForChild("XP").Value >= player:WaitForChild("XPNeeded").Value then
levelz.Value = levelz.Value+1
xpn.Value = xpn.Value+1000
savedata("Levels",player.userId,levelz.Value)
savedata("XP",player.userId,xpz.Value)
savedata("AXP",player.userId,xpn.Value)
else
savedata("Levels",player.userId,levelz.Value)
savedata("XP",player.userId,xpz.Value)
savedata("AXP",player.userId,xpn.Value)
end
savedata("Levels",player.userId,levelz.Value)
savedata("XP",player.userId,xpz.Value)
savedata("AXP",player.userId,xpn.Value)
end)
end)

game.Players.PlayerRemoving:connect(function(player)
savedata("Levels",player.userId,player.leaderstats.Level.Value)
savedata("XP",player.userId,player.XP.Value)
savedata("AXP",player.userId,player.XPNeeded.Value)
end)


R$14
Report Abuse
Naxxanar is not online. Naxxanar
Joined: 13 Jun 2012
Total Posts: 709
17 Sep 2016 05:39 AM
is it in a localscript?


#code warn('I did', #'10' + 9 + 7 + 1 - 8 + 900);
Report Abuse
EvolutionPower is not online. EvolutionPower
Joined: 16 Dec 2013
Total Posts: 873
17 Sep 2016 05:41 AM
No, should it be?


R$14
Report Abuse
vexieh is not online. vexieh
Joined: 22 Oct 2009
Total Posts: 3468
17 Sep 2016 05:43 AM
If the top script isn't in a LocalScript then you may need to go revise how LocalPlayer works.


Report Abuse
EvolutionPower is not online. EvolutionPower
Joined: 16 Dec 2013
Total Posts: 873
17 Sep 2016 05:44 AM
Even with it being a local script, the whole leaderstats wont even clone into player but normal scripts = it does


R$14
Report Abuse
vexieh is not online. vexieh
Joined: 22 Oct 2009
Total Posts: 3468
17 Sep 2016 05:52 AM
LocalScripts only run in places like StarterGui, StarterPack or ReplicatedFirst

It'd be a terrible idea to have a local leaderstat anyway


Report Abuse
Kurokku is not online. Kurokku
Joined: 01 Aug 2015
Total Posts: 3622
17 Sep 2016 05:53 AM
well I personally think adding the leaderstats part to the code is a must do or else it'll error out here ya go

while true do
wait(6)
game.Players.LocalPlayer.leaderstats.XP.Value = game.Players.LocalPlayer.leaderstats.XP.Value + 30
end
Report Abuse
EvolutionPower is not online. EvolutionPower
Joined: 16 Dec 2013
Total Posts: 873
17 Sep 2016 05:54 AM
The xp's parent isnt in leaderstats.


R$14
Report Abuse
vexieh is not online. vexieh
Joined: 22 Oct 2009
Total Posts: 3468
17 Sep 2016 05:54 AM
@Kurokku
I hope you're joking


Report Abuse
EvolutionPower is not online. EvolutionPower
Joined: 16 Dec 2013
Total Posts: 873
17 Sep 2016 05:55 AM
##########################################################################################################################################################################################################################################################################################################################################################################################################################################################end

game.Players.PlayerAdded:connect(function(player)
local leader = Instance.new("Folder")
leader.Name = "leaderstats"
leader.Parent = player
local levelz = Instance.new("IntValue")
levelz.Value = level:GetAsync(tostring(player.userId)) or 1
levelz.Name = "Level"
levelz.Parent = player:WaitForChild("leaderstats")
local xpz = Instance.new("NumberValue")
xpz.Value = XP:GetAsync(tostring(player.userId))
xpz.Name = "XP"
xpz.Parent = player
local xpn = Instance.new("IntValue")
xpn.Value = AXP:GetAsync(tostring(player.userId)) or 500
xpn.Name = "XPNeeded"
xpn.Parent = player
while true do
wait(6)
player:WaitForChild("XP").Value = player:WaitForChild("XP").Value + 30

xpz.Changed:connect(function()
if player:WaitForChild("XP").Value >= player:WaitForChild("XPNeeded").Value then
levelz.Value = levelz.Value+1
xpn.Value = xpn.Value+1000
savedata("Levels",player.userId,levelz.Value)
savedata("XP",player.userId,xpz.Value)
savedata("AXP",player.userId,xpn.Value)
else
savedata("Levels",player.userId,levelz.Value)
savedata("XP",player.userId,xpz.Value)
savedata("AXP",player.userId,xpn.Value)
end
end)
savedata("Levels",player.userId,levelz.Value)
savedata("XP",player.userId,xpz.Value)
savedata("AXP",player.userId,xpn.Value)
end
end)

game.Players.PlayerRemoving:connect(function(player)
savedata("Levels",player.userId,player.leaderstats.Level.Value)
savedata("XP",player.userId,player.XP.Value)
savedata("AXP",player.userId,player.XPNeeded.Value)
end)



Why doesn't it give 30 xp every 6 seconds but it decides to give 30 xp randomly at times? But now, it does work, just the seconds..


R$14
Report Abuse
Kurokku is not online. Kurokku
Joined: 01 Aug 2015
Total Posts: 3622
17 Sep 2016 05:56 AM
Okay but still you are working with datastores and not once have I seen you define where you need to set the async to the datastore

And you didn't even add a playeradded function so that when the player joins it adds the folder into him/her
Report Abuse
EvolutionPower is not online. EvolutionPower
Joined: 16 Dec 2013
Total Posts: 873
17 Sep 2016 05:57 AM
game.Players.PlayerAdded:connect(function(player)
local leader = Instance.new("Folder")
leader.Name = "leaderstats"
leader.Parent = player


R$14
Report Abuse
Kurokku is not online. Kurokku
Joined: 01 Aug 2015
Total Posts: 3622
17 Sep 2016 05:58 AM
Why would you put a while true do function inside the player added it's just gonna break the whole script
Report Abuse
vexieh is not online. vexieh
Joined: 22 Oct 2009
Total Posts: 3468
17 Sep 2016 05:58 AM
He does have a PlayerAdded function though?

Question: Without the adding 30 exp per 6 seconds does everything else actually work? leaderstats added and saves?


Report Abuse
EvolutionPower is not online. EvolutionPower
Joined: 16 Dec 2013
Total Posts: 873
17 Sep 2016 05:59 AM
yep.


R$14
Report Abuse
Kurokku is not online. Kurokku
Joined: 01 Aug 2015
Total Posts: 3622
17 Sep 2016 05:59 AM
He's setting the async to the players user id. He didn't even have a datastore service meaning that the whole saving and loading thing won't work
Report Abuse
vexieh is not online. vexieh
Joined: 22 Oct 2009
Total Posts: 3468
17 Sep 2016 06:00 AM
Then just put this in a script in Workspace

local ExpIncrease = 30

while wait(6) do
for i,v in pairs(game.Players:GetChildren()) do
if(v:FindFirstChild("leaderstats")~=nil)then
if(v.leaderstats:FindFirstChild("XP")~=nil)then
v.leaderstats.XP.Value = v.leaderstats.XP.Value + ExpIncrease
end
end
end
end


Report Abuse
EvolutionPower is not online. EvolutionPower
Joined: 16 Dec 2013
Total Posts: 873
17 Sep 2016 06:01 AM
I do but it's in tags when i post it


R$14
Report Abuse
EvolutionPower is not online. EvolutionPower
Joined: 16 Dec 2013
Total Posts: 873
17 Sep 2016 06:03 AM
i guess that's local >.>


R$14
Report Abuse
Kurokku is not online. Kurokku
Joined: 01 Aug 2015
Total Posts: 3622
17 Sep 2016 06:03 AM
Ye problem is that your putting the while true do function above everything else in the script so it won't even work, put this function at the very bottom of the code
Report Abuse
vexieh is not online. vexieh
Joined: 22 Oct 2009
Total Posts: 3468
17 Sep 2016 06:04 AM
No, it's not local and it should be in it's own script..


Report Abuse
EvolutionPower is not online. EvolutionPower
Joined: 16 Dec 2013
Total Posts: 873
17 Sep 2016 06:04 AM
?


R$14
Report Abuse
EvolutionPower is not online. EvolutionPower
Joined: 16 Dec 2013
Total Posts: 873
17 Sep 2016 06:06 AM
can u please edit that? the XP parent is the player, like game.Players.LocalPlayer.XP


R$14
Report Abuse
vexieh is not online. vexieh
Joined: 22 Oct 2009
Total Posts: 3468
17 Sep 2016 06:09 AM
local ExpIncrease = 30

while wait(6) do
for i,v in pairs(game.Players:GetChildren()) do
if(v:FindFirstChild("XP")~=nil)then
v.XP.Value = v.leaderstats.XP.Value + ExpIncrease
end
end
end


Report Abuse
vexieh is not online. vexieh
Joined: 22 Oct 2009
Total Posts: 3468
17 Sep 2016 06:10 AM
Oops I'm a total idiot..

Ignore the above code, if the XP's parent is the player then this should work

local ExpIncrease = 30

while wait(6) do
for i,v in pairs(game.Players:GetChildren()) do
if(v:FindFirstChild("XP")~=nil)then
v.XP.Value = v.XP.Value + ExpIncrease
end
end
end


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