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

How do I add a player variable to my script?

Asked by 5 years ago
Edited 5 years ago

how do I make a player variable? Like how everyone has a different health value. Server variable example is: How long the server has been up Player variable example is: How long a player has been on the server.

I’m asking this because I want to make everyone have a different gold value.

Edit: Sorry for the vagueness. So what I want is like a leaderboard system, like what PainterTable Said.

0
r u gonna use data store to save the amount of gold? HappyTimIsHim 652 — 5y
0
also to get a player variable u need to do game.Players.LocalPlayer (only in local scripts because a server script isn't used to find specific player values) HappyTimIsHim 652 — 5y
0
??* User#19524 175 — 5y
0
This doesn't make a lick of sense. DinozCreates 1070 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

I think what you're asking is a leaderboard system. with this way you could check how long a player is on the server this session and how much gold he has.

Example leaderboard

    local function onPlayerJoin(player)
        local leaderstats = Instance.new("Folder")
        leaderstats.Name = "leaderstats"
        leaderstats.Parent = player

        local gold = Instance.new("IntValue")
        gold.Name = "Gold"
        gold.Value = 0
        gold.Parent = leaderstats

    local.time = Instance.new("IntValue")
    time.Name = "Time"
    time.Value = 0
    time.Parent = leaderstats
    end

With this you have a folder in each Player with 2 Stats called gold and time. Now you could also do an easy function to make the IntValue in Time go up 1 every second. If you do that you can check with print how long the player is on the server or make a GUI and display it there. I just gave you the beginning.

Example of Time Function

while true do
wait(1)
time.Value = time.Value + 1
end

(I dont know if this works, Roblox is down right now) But if this works you need to place it in the same script, right under my Lines up there.

0
Also if you would like to save all these informations it would take up even more effort. Paintertable 171 — 5y
0
Thank you! This is exactly what I wanted! Noonekirby 162 — 5y
0
No Problem :) If you have more question ask me :) Paintertable 171 — 5y
0
How do I make it so I can put the time function or a gold function in another script? Noonekirby 162 — 5y
Ad

Answer this question