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

Can i transfer a datastore through places?

Im trying to transfer a single datastore through a place but it doesnt work and i dont know how to make it work. My main places datastore script has this code and id like it to transfer between the places:

local dataStoreService = game:GetService("DataStoreService")
local myDataStore = dataStoreService:GetDataStore("myDataStore")

game.Players.PlayerAdded:Connect(function(player)
    
    local leaderstats = Instance.new("Folder", player)
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player
    
    local Nights = Instance.new("IntValue", leaderstats)
    Nights.Name = "Nights"
    Nights.Value = 0
    Nights.Parent = leaderstats
        
    local playerUserId = "Player_"..player.UserId
    
    -- load data
    
    local data
    local success, errormessage = pcall(function()
        data = myDataStore:GetAsync(playerUserId)
    end)    

    if success then
        -- set data 
        Nights.Value = data
    end
    
end)

game.Players.PlayerRemoving:Connect(function(player)
    local playerUserId = "Player_"..player.UserId
    local data = player.leaderstats.Nights.Value
    local success, errormessage = pcall(function()
        myDataStore:SetAsync(playerUserId, data)
    end)
    
    if success then
        print("Data successfully saved")
    else 
        print("Error happened")
        warn(errormessage)
    end
end)

To teleport to that place i have this script:

local TPS = game:GetService("TeleportService")

script.Parent.MouseButton1Click:Connect(function(player)
	local datastore = game.Players.LocalPlayer:WaitForChild("leaderstats").Nights
	local player = game.Players.LocalPlayer
	script.Parent.Parent.pleasewait.Visible = true
	TPS:GetTeleportSetting(datastore)
	TPS:Teleport(5616570036, player)
end)

And the script inside that place i want to teleport to gives me an error "WaitForChild is not a valid member of RBXScriptSignal, here is the code:

local leaderstats = game.Players.PlayerAdded:WaitForChild("leaderstats")
local nights = leaderstats.Nights

script.Parent.ClickDetector.MouseClick:Connect(function()
	nights.Value = nights.Value + 1
end)

To clarify: Im trying to make it so a datastore script is accessible through multiplie places, and when i change the value of a leaderstat stat inside the new place it saves into the datastore and is accessible in the starting place.

2 comments

0

You can use a external webserver and database to do that, datastores are only shared if both places are on the same universe

0

You don't need an external database to keep data among places in a game. It's already a built-in feature that datastores are for entire games and not single places within the game.

2 answers

To access the same datastore from different places (so long as they're part of the same game) all you have to do is set the pathway to the datastore to be the same in each place...

"WaitForChild is not a valid member of RBXScriptSignal" is telling you that you cannot use the method:WaitForChild() on the end of .playerAdded, the only methods you can call from playerAdded are :wait() and :connect()

3 comments

0

do you mind telling me how do i set a pathway? do i have to just copy the code of the original datastore and paste it into the new place?

0

do i have to just copy the code from the original datastore script and paste it inside the new place for this to work?

0

by pathday I just mean make the variable you're calling "local myDataStore" point to the same DataStore from both places :) so "dataStoreService:GetDataStore("myDataStore")" in the script which communicates with the datastore in each place :) I hope that helps!

The error in your script is a simple fix:

game.Players.PlayerAdded:Connect(Player)
	Player:WaitForChild("leaderstats")
	local nights = leaderstats.Nights

	script.Parent.ClickDetector.MouseClick:Connect(function()
 	   nights.Value = nights.Value + 1
	end)
end

You just skipped a step when connecting the event.

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