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: Hunger and Thirst leaderboard script doesn't work

Previous Thread :: Next Thread 
max659 is not online. max659
Joined: 01 Nov 2009
Total Posts: 84
07 Aug 2015 07:49 PM
Hey! I am trying to make a hunger and thirst leaderboard but when I test it out it only one of them decreases. Any ideas on how to make both of them decrease?


Here's the line of code

_________________________________

game.Players.PlayerAdded:connect(function(player)

local stats = Instance.new("IntValue", player)
stats.Name = "leaderstats"

local hunger = Instance.new("IntValue", stats)
hunger.Name = "Hunger"
hunger.Value = 100

local thirst = Instance.new("IntValue", stats)
thirst.Name = "Thirst"
thirst.Value = 100

while true do
wait(1)
player.leaderstats.Thirst.Value = player.leaderstats.Thirst.Value - 1
wait(1)
player.leaderstats.Hunger.Value = player.leaderstats.Hunger.Value - 1
end
end)

Report Abuse
togov is not online. togov
Joined: 21 Apr 2010
Total Posts: 3740
07 Aug 2015 07:55 PM
1 Make two scripts
1. where it checks if player is in game because the script can only carry out 1 command at a time so many players can spawn in and there will be delays

2. The damager

game.Players.PlayerAdded:connect(function(player)
repeat wait () until player ~= nil
local stats = Instance.new("IntValue", player)
stats.Name = "leaderstats"
repeat wait () until stats ~= nil
local hunger = Instance.new("IntValue", stats)
hunger.Name = "Hunger"
hunger.Value = 100
repeat wait () until hunger ~= nil
local thirst = Instance.new("IntValue", stats)
thirst.Name = "Thirst"
thirst.Value = 100
local dmg = Game.Lighting.Script2:Clone()
dmg.Parent = player
script two Make it local

while true do

wait(1)
player:WaitForChild("leaderstats").Thirst.Value = player.leaderstats.Thirst.Value - 1
wait(1)
player:WaitForChild("leaderstats").Hunger.Value = player.leaderstats.Hunger.Value - 1
end
Report Abuse
CrowClaws is not online. CrowClaws
Joined: 04 Jul 2010
Total Posts: 4466
07 Aug 2015 07:56 PM
@togov

You have no clue what you are talking about.
Report Abuse
max659 is not online. max659
Joined: 01 Nov 2009
Total Posts: 84
07 Aug 2015 07:56 PM
Oh ok. Thanks for the help
Report Abuse
CrowClaws is not online. CrowClaws
Joined: 04 Jul 2010
Total Posts: 4466
07 Aug 2015 07:56 PM
"the script can only carry out 1 command at a time "

??? What are you talking about ???
Report Abuse
togov is not online. togov
Joined: 21 Apr 2010
Total Posts: 3740
07 Aug 2015 07:58 PM
Crow the script he made was looped so it wouldn't work for more than two players.
Report Abuse
max659 is not online. max659
Joined: 01 Nov 2009
Total Posts: 84
07 Aug 2015 08:03 PM
I tried out the script but it still didn't work. It seems putting it in a different script made it worse(no offense). Now none of the stats are decreasing.
Report Abuse
max659 is not online. max659
Joined: 01 Nov 2009
Total Posts: 84
07 Aug 2015 08:13 PM
Yeah, the new script won't even let one of the decrease
Report Abuse
togov is not online. togov
Joined: 21 Apr 2010
Total Posts: 3740
07 Aug 2015 08:15 PM
while true do

wait(1)
player:WaitForChild("leaderstats").Thirst.Value = player:WaitForChild("leaderstats").Thirst.Value- 1
wait(1)
player:WaitForChild("leaderstats").Hunger.Value = player:WaitForChild("leaderstats").Thirst.Value- 1
end
Report Abuse
max659 is not online. max659
Joined: 01 Nov 2009
Total Posts: 84
07 Aug 2015 08:19 PM
It won't work because the other script has a parameter of player and nothing can use that parameter unless it is in the function. I know you probably know this but just to clarify
Report Abuse
lomo0987 is not online. lomo0987
Joined: 31 May 2008
Total Posts: 2461
07 Aug 2015 08:21 PM
You are going to want 2 scripts... 1 the first one will be in workspace

game.Players.PlayerAdded:connect(function(player)

local stats = Instance.new("IntValue", player)
stats.Name = "leaderstats"

local hunger = Instance.new("IntValue", stats)
hunger.Name = "Hunger"
hunger.Value = 100

local thirst = Instance.new("IntValue", stats)
thirst.Name = "Thirst"
thirst.Value = 100

end)

This 2nd one will be a local script inside StarterGui

wait(2)
player = game.Players.LocalPlayer

while true do
wait(2)
player.leaderstats.Thirst.Value = player.leaderstats.Thirst.Value - 2
player.leaderstats.Hunger.Value = player.leaderstats.Hunger.Value - 1
end
Report Abuse
max659 is not online. max659
Joined: 01 Nov 2009
Total Posts: 84
07 Aug 2015 08:22 PM
Ok thanks, I'll try it out
Report Abuse
max659 is not online. max659
Joined: 01 Nov 2009
Total Posts: 84
07 Aug 2015 08:24 PM
Thank you so much! It worked!
Report Abuse
ShungTzu is not online. ShungTzu
Joined: 14 Jun 2014
Total Posts: 959
07 Aug 2015 08:26 PM
There's nothing wrong with it.

What else does the script say?
Report Abuse
max659 is not online. max659
Joined: 01 Nov 2009
Total Posts: 84
07 Aug 2015 08:27 PM
Shung the thing wrong with it was that it would only decrease one of the stats not both
Report Abuse
ScripterTony is not online. ScripterTony
Joined: 26 Nov 2012
Total Posts: 5257
07 Aug 2015 08:28 PM
I've fixed your script, and it's shorter, and only needs to be in one script that is in ServerScriptService

game.Players.PlayerAdded:connect(function(player)
local stats = Instance.new("IntValue", player)
local ints = {"Hunger", "Thirst"}

stats.Name = "leaderstats"

for i,v in pairs(ints) do
local int = Instance.new("IntValue", stats)
int.Name = v
int.Value = 100
end

while wait(1) do
player.leaderstats.Thirst.Value = player.leaderstats.Thirst.Value - 1
player.leaderstats.Hunger.Value = player.leaderstats.Hunger.Value - 1
end
end)
Report Abuse
CrowClaws is not online. CrowClaws
Joined: 04 Jul 2010
Total Posts: 4466
07 Aug 2015 08:30 PM
@togov

you can have a loop inside an event
do u even event?

This for example would work fine:

game.Players.PlayerAdded:connect(function(p)
while wait() do
print(p.Name)
end
end)

if you had to players join it would print both of their names. (not on the same line)

Report Abuse
max659 is not online. max659
Joined: 01 Nov 2009
Total Posts: 84
07 Aug 2015 08:32 PM
Lomo since you helped me with the script I will make it a model and you will have credit ^_^
Report Abuse
ShungTzu is not online. ShungTzu
Joined: 14 Jun 2014
Total Posts: 959
07 Aug 2015 08:34 PM
It didn't. It decreased both of them every second, for each player independently. I can tell by looking at it that that's what it will do, but, before I responded, I bothered to test it, and it did exactly that for 3 players.

Something else was interfering and, if you change it locally, and then, later, decide to set FilteringEnabled to true, which probably will happen, you'll have to remake the whole scheme.
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