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

Leaderboard and leaderstats problem?

Asked by 4 years ago
Edited 4 years ago

There is my script to make the leaderboard:


game.Players.PlayerAdded:connect(function(player) local leaderstats = Instance.new("Model") leaderstats.Name = "leaderstats" leaderstats.Parent = player local money = Instance.new("IntValue") --We create a new IntValue money.Name = "Money" --this is the name you want the leader-stat to be when it shows up in-game. --this is the value of money the new player starts out with. To change this, you can add some more code (shown later) money.Parent = leaderstats -- Set the money object as a child of the leaderstats object. end)

and there is my script to add point to leaderboard:

while true do
wait(1)
game.Players.LocalPlayer.leaderstats.Money.Value = 1
end

Why my money stay to 0?

3 answers

Log in to vote
0
Answered by 4 years ago

if the code that listens for when a player enters a server is in a local script, then it won't make the leaderboard at all;

and also, if the code that is suppose to increase/decrease the amount is in local script then, you the amount will only increase on player's screen...

so make you sure you use server scripts on both;

exampe:

in server script

game.Players.PlayerAdded:Connect(function(player)
    local stat = instance.new("Folder", player) -- makes new folder and puts it in player object'
    stat.Name = "leaderstats"

    local money = instance.new("IntValue",stat)
    money.Name = "Money"
    Money.Value = 0
end)

in another server script; even tho you can technically use same script, but make sure the following code is below the above code, if your using same script

wait(5) -- to make sure it doesn't run immediately after server startup 
local cashPerSecond = 20
while wait(1) do
    for _, player in pairs(game.Players:GetPlayers()) do
        local stat = player:WaitForChild("leaderstats")
        local money = stat:WaitForChild("Money")

        money.Value = money.Value + cashPerSecond
    end
end
0
lol it wouldnt work in ReplicatedStorage soooooo WikiBaseHealthFinder 40 — 4y
0
why would you put it in replicated storage?? User#23252 26 — 4y
0
also making a folder is rather stupid and takes long, you can make one and clone it whenever they join WikiBaseHealthFinder 40 — 4y
0
because putting it in replicatedstorage can allow me to use parent to quickly get the values WikiBaseHealthFinder 40 — 4y
0
do you even know what your saying?? because you aren't making sense.. User#23252 26 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

u cannot do that but u can

local function setVal(val,newVal)
    local x = Instance.new(val.ClassName, val.Parent)
    x.Name = val.Name
    val:Destroy()
    x.Value = newVal
end
setVal(money,1)
0
basically destroy the value and make a new one WikiBaseHealthFinder 40 — 4y
0
terrible answer User#23252 26 — 4y
0
how is this terrible? it fix the thing and it can be changed dynamically? whats the issue? WikiBaseHealthFinder 40 — 4y
0
just sayin, but that approach isn't very friendly User#23252 26 — 4y
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

You have to make it in the same script like this put this in the same script


while true do wait(1)--- change to how long it must take to get the money money.Value = money.Value +1 --- change "+1" to how much money you get (don't touch the plus unless you want it to - the stuff then say -1 or what ever) wait() end
0
5/10 User#23252 26 — 4y
0
i try it scorpion981 27 — 4y
0
it wouldnt work lol WikiBaseHealthFinder 40 — 4y
0
sorry but what i want its a script in the workspace (for complicated reason) scorpion981 27 — 4y
0
try again i edited it GamerJanko 50 — 4y

Answer this question