Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to send leader stats across multiple games?

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

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

3 comments

0

How do I do this?

0

Unsure, something with HTTP for sure.

0

oh

This discussion is preserved as it was. New answers, comments, and votes are closed.