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

How to transfer data between Places?

Despite my research from the internet, nothing I do works. How do I transfer Data between Place? I copied the following script to both Places as a script: (In ServerScriptService)

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

game.Players.PlayerAdded:Connect(function(Player)
    local leaderstats = Instance.new("Folder", Player)
	leaderstats.Name = "leaderstats"
 
	local Rebirths = Instance.new("IntValue", leaderstats)
	Rebirths.Name = "Rebirths"
	Rebirths.Value = 0
 
	local Jumps = Instance.new("IntValue", leaderstats)
	Jumps.Name = "Jumps"
	Jumps.Value = 50
	
	local Gems = Instance.new("IntValue", leaderstats)
	Gems.Name = "Gems"
	Gems.Value = 0
 
    local Data = DataStore:GetAsync(Player.UserId)
	if Data then
        Rebirths.Value = Data.Rebirths
		Jumps.Value = Data.Jumps
		Gems.Value = Data.Gems
		if Data.Jumps < 50 then
			Jumps.Value = 50
			Data.Jumps = 50
		end
	else
		warn("Data equals to false for", Player.Name)
		Jumps.Value = 50
	end
end)
 
game.Players.PlayerRemoving:Connect(function(player)
	DataStore:SetAsync(player.UserId, {
		["Rebirths"] = player.leaderstats.Rebirths.Value;
		["Jumps"] = player.leaderstats.Jumps.Value;
		["Gems"] = player.leaderstats.Rebirths.Value;
	})
end)


The script I use to teleport from the first place to the second place is:

local TeleportService = game:GetService("TeleportService")
local Place = 9968872946
local tpGui = game.ReplicatedStorage.TeleportGui

script.Parent.Touched:Connect(function(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if player then
		TeleportService:SetTeleportGui(tpGui)
		TeleportService:Teleport(Place, player)
	end
end)

1 answer

Since I could not solve this, I decided to use teleport data and the problem was solved. Teleport Script:

script.Parent.Touched:Connect(function(hit)
	local TeleportService = game:GetService("TeleportService")
	local placeId = 9968872946

	local Players = game:GetService("Players")
	local player = Players:GetPlayerFromCharacter(hit.Parent)
	if player then
		local teleportData = {
			Jumps = player.leaderstats.Jumps.Value,
			Rebirths = player.leaderstats.Rebirths.Value,
			Gems = player.leaderstats.Gems.Value
		}
		TeleportService:Teleport(placeId, player, teleportData)
	end
end)

Local Script for get teleport data: (In StarterPlayerScripts)

local TeleportService = game:GetService("TeleportService")
local player = game.Players.LocalPlayer
wait(5)
local teleportData = TeleportService:GetLocalPlayerTeleportData()
if teleportData then
	player.leaderstats.Jumps.Value = teleportData.Jumps
	player.leaderstats.Rebirths.Value = teleportData.Rebirths
	player.leaderstats.Gems.Value = teleportData.Gems
end

2 comments

0

That's the solution, but I don't think I can mark my own message as the solution.

0

Can you close the thread?

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