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

How to send leader stats across multiple games?

Asked by 4 years ago

I am new to this, how do I send the money to another game? Do we I data store? Here is the example code:

Original Game:

local players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("SaveCashV2.0")

local cashValue = 100000

local function Save(plr)
    local key = "plr-"..plr.UserId

    local save = {
        ["Cash"] = plr.leaderstats.Cash.Value
    }

    local success, err = pcall(function()
        DataStore:SetAsync(key, save)
    end)

    if not success then
        warn("Failed to over-read data: "..tostring(err))
        return
    end
end

local function Load(plr)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = plr

    local currency = Instance.new("IntValue")
    currency.Name = "Cash"
    currency.Value = cashValue
    currency.Parent = leaderstats

    local stringValue = Instance.new("StringValue")
    stringValue.Name = "Character"
    stringValue.Parent = plr
    stringValue.Value = stringValue.Parent.Name

    --DataStore Below   

    local key = "plr-"..plr.UserId

    local savedData

    local success, err = pcall(function()
        savedData = DataStore:GetAsync(key)
    end)

    if not success then
        warn("Failed to read data: "..tostring(err))
        return
    end

    if savedData then
        currency.Value = savedData.Cash
    else
        Save(plr)
    end
end

players.PlayerAdded:Connect(Load)
players.PlayerRemoving:Connect(Save)

Other Game: same script as above

Teleportation Script:

local teleportService = game:GetService("TeleportService")
local place = 2523341335 --change to the teleport place

script.Parent.Touched:Connect(function(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if player then
        --teleportService:Teleport(place, player)
        teleportService:Teleport(place, player, game.Players.LocalPlayer)
    end
end)

Thanks for the Help!

1 answer

Log in to vote
2
Answered by
0_2k 496 Moderation Voter
4 years ago

Apparently, Roblox data stores aren't able to do this. If you use an external datastore to store data, you'll be good.

0
How do I do this? awesomemode14 68 — 4y
0
Unsure, something with HTTP for sure. 0_2k 496 — 4y
0
oh awesomemode14 68 — 4y
Ad

Answer this question