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

How to teleport data player to another place?

So i look at youtube how to do it but i look on the comments u can just use datastore, now im confused and i try this script

local dsservice = game:GetService("DataStoreService")
local ds = dsservice:GetDataStore("PlayerData")

game.Players.PlayerAdded:Connect(function(player)
	
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local crystal = Instance.new("IntValue")
	crystal.Name = "Crystal"
	crystal.Parent = leaderstats
	
	local level = Instance.new("IntValue")
	level.Name = "Level"
	level.Parent = leaderstats
	
	local win = Instance.new("IntValue")
	win.Name = "Win"
	win.Parent = leaderstats
	
	local id = "Player_" ..player.UserId
	
	local data
	local success, errorMessage = pcall(function()
		data = ds:GetAsync(id)
	end)
	
	if success then
		crystal.Value = data
	else
		warn(errorMessage)
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
	
	local id = "Player_"..player.UserId
	
	local data = player.leaderstats.Crystal.Value
	
	local success, errorMessage = pcall(function()
		ds:SetAsync(id, data)
	end)
	
end)

but still don't work (maybe because im using roblox studio not roblox player?) Can u guys help me?

2 comments

0

what data do you wanna teleport

0

The level and crystal and win and like if the player have a value and its true on the lobby then on the game he will have a sword

2 answers

✓ Accepted answer

Here's a tutorial on how to send data to another game Youtube Hope this helps!!

If you want to load muliple data then you will have to use table like

local data = {
	player.leaderstats.ValueName.Value;
	player.leaderstats.ValueName.Value;
}

Here is a related example to your script (you can just copy paste it):

local dsservice = game:GetService("DataStoreService")
local ds = dsservice:GetDataStore("PlayerData")

game.Players.PlayerAdded:Connect(function(player)

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

    local crystal = Instance.new("IntValue")
    crystal.Name = "Crystal"
    crystal.Parent = leaderstats

    local level = Instance.new("IntValue")
    level.Name = "Level"
    level.Parent = leaderstats

    local win = Instance.new("IntValue")
    win.Name = "Win"
    win.Parent = leaderstats

    local id = "Player_" ..player.UserId

    local data
    local success, errorMessage = pcall(function()
        data = ds:GetAsync(id)
    end)

    if success then
        crystal.Value = data
    else
        warn(errorMessage)
    end
end)

game.Players.PlayerRemoving:Connect(function(player)

    local id = "Player_"..player.UserId

    local data = {
		player.leaderstats.Crystal.Value;
		player.leaderstats.Level.Value;
		player.leaderstats.Win.Value;
}

    local success, errorMessage = pcall(function()
        ds:SetAsync(id, data)
    end)

end)

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