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

need some help with a script that increases your money every second or so. :?

Asked by 4 years ago

I made a separate script I put in the workspace to pay the player but it's not working at all

pay script

game.Players.PlayerAdded:Connect(function(plr)
    while wait(0.5) do
    plr.stats.Money.Value = plr.stats.Money.Value + 0.1
    end
end)

leaderboard (leaderstats being called stats being intensional)

game.Players.PlayerAdded:Connect(function(plr)
    local s = Instance.new("Folder")
    s.Name = "stats"
    s.Parent = plr

    local money = Instance.new("IntValue")
    money.Name = "Money"
    money.Parent = s

    while wait(0.5) do
    plr.stats.Money.Value = plr.stats.Money.Value + 0.1
    end
end)
0
You should debug your code and figure out when things are running and other details and provide your debugging results. See https://scriptinghelpers.org/help/question-not-descriptive for details hiimgoodpack 2009 — 4y

2 answers

Log in to vote
0
Answered by
ArtBlart 533 Moderation Voter
4 years ago
Edited 4 years ago

There is a few layers to your question here. The main reason why your script doesn't work is because the folder is actually required to be called leaderstats. If it is not, the value will not show on the leaderboard.

Secondly, the reason why your value will not change is because of the value type you are using. An integer is defined as a whole number; a number that is not a fraction. Since decimals can represent fractions, and fractions can represent decimals EX: .5 = 1/2, any attempt to add a non-integer value to the intvalue will fail. What you need is a NumberValue. It functions much in the same way as an intvalue but can be used to store non-integer values, such as 0.2.

Hope this helps! If you have any further questions feel free to comment or look things up on the devforum.

Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

I think your saying every player gets cash every 0.5 seconds. Here is my answer if that is true.

So I'm not to sure why this does not work specifically but I know a solution, in order to make everyone's money increase every 0.5 seconds we need to place a script that increases everyone's money every time.

So put your script in ServerScriptService, make sure it is a server-side script, not a module script or a local script.

In order to do this we are going to use a infinite loop.

So starting our script like this:

local players = game.Players:GetPlayers()
local waitTime = 0.5
local cashAdded - 0.1

while true do

    wait(waitTime)
end

Next we are going to iterate, which just means looping through a table.

local players = game.Players:GetPlayers()
local waitTime = 0.5
local cashAdded = 0.1

while true do
    for i,v in pairs(players) do

    end

    wait(waitTime)
end

Then we are going to give everyone extra cash.

local players = game.Players:GetPlayers()
local waitTime = 0.5
local cashAdded = 0.1

while true do
    for i,v in pairs(players) do
        v.leaderstats.Money.Value = v.leaderstats.Money.Value + cashAdded
    end

    wait(waitTime)
end

I bet you are confused right now, since you may not know about tables or iterating. I suggest you learn more now and try to make things after. Here is an article about tables: https://developer.roblox.com/en-us/articles/Table

It may be confusing but try to use your background knowledge. You can ask me clarification anytime :)

EDIT: Like ArtBlart stated, your Folder name should be "leaderstats" instead of "stats" and adding decimals to leaderstats is probably a bad idea.

Answer this question