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

How to teleport data player to another place?

Asked by
thifal2 14
1 year ago

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?

0
what data do you wanna teleport Puppynniko 1059 — 1y
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 thifal2 14 — 1y

2 answers

Log in to vote
0
Answered by 1 year ago

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

Ad
Log in to vote
0
Answered by 1 year ago
Edited 1 year ago

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)

Answer this question