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

Help with data stores/data persistance?

Asked by
NRCme 0
8 years ago

I need the game to save a 4 number sequence with a dot in between the numbers(so only uses one data store) I've looked through Data Persistance and Data Stores but I can't figure it out...

I've written many lines of code that use Data persistence but I can't get anything to work in that at all

(my code is supposed to write the IP to a leaderboard)

the code that I wrote:

local DataStore = game:GetService("DataStoreService"):GetDataStore("IP") 

local IP = "0.11.4.99"
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 = "IP" --this is the name you want the leader-stat to be when it shows up in-game.
        money.Value = IP --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)
game.Players.PlayerRemoving:connect(function(p)---set played to true-------------------------------------------------------------------
    p:WaitForDataReady()
    local played = p:LoadBoolean("Played")
    if played == false then

        played = true       
    end
end)


game.Players.PlayerAdded:connect(function(p)------------------------------------creating new IP----------------------------------------------
    p:WaitForDataReady()
    local played = p:LoadBoolean("Played")
    if played == false then

        local rndm1 = math.random(254)
        local rndm2 = math.random(254)
        local rndm3 = math.random(254)
        local rndm4 = math.random(254)
        IP = rndm1.. ".".. rndm2.. ".".. rndm3.. ".".. rndm4

        print(IP)
    end
end)

print(IP)
game.Players.PlayerAdded:connect(function(player)----------------------------------------------------------------------------------------
    player:WaitForDataReady()
    local played = player:LoadBoolean("Played")
    if played == false then
        player:SaveString("IP", IP)
    end
end)


game.Players.PlayerAdded:connect(function(p)------------------Load IP---------------------------------------------------------------------
    p:WaitForDataReady()

    local IP = p:LoadString("IP")
end)

the leaderboard is always 0 not matter what(also sorry the code is a bit messy)

If anyone has a better way I should do this or a fix for it, it would be appreciated!

0
https://www.youtube.com/watch?v=tOOS9lMIYes maybe this will help? Jumbuu 110 — 8y
0
thanks that helped! NRCme 0 — 8y

1 answer

Log in to vote
0
Answered by
Cuvette 246 Moderation Voter
8 years ago

You're trying to use IntValue when you're dealing with Float's. A typical IntValue won't recognise the decimal places, I'm not too strong on this subject because I've never had to deal with Floats in a leaderboard.

But my best guess would be to convert it to a string and place that into the leaderboard, then convert it back whenever you need it.

I'm sure there are much easier ways around this.

0
That helped to! NRCme 0 — 8y
0
(that kinda got my mind thinking and I actually assigned it as a string) NRCme 0 — 8y
Ad

Answer this question