Ok so here is what you need to do. In Main Game AND Obby I want you to make a script and put it in SSS. It will be your player stats (Make sure to have API Access enabled in game settings). Below is the script.
local DataStoreService = game:GetService("DataStoreService")
local playerData = DataStoreService:GetDataStore("RagdollCenter")
local function onPlayerJoin(player)
local PlayerStats = Instance.new("Folder")
PlayerStats.Name = "PlayerStats"
PlayerStats.Parent = player
--//Stats\\--
local Coins = Instance.new("NumberValue")
Coins.Name = "Coins"
Coins.Parent = PlayerStats
local Stage = Instance.new("NumberValue")
Stage.Name = "Stage"
Stage.Parent = PlayerStats
local playerUserId = "Player_" .. player.UserId
local data = playerData:GetAsync(playerUserId)
if data then
Coins.Value = data['Coins']
Stage.Value = data['Stage']
else
Coins.Value = 0
Stage.Value = 0
end
end
local function create_table(player)
local player_stats = {}
for _, stat in pairs(player.PlayerStats:GetChildren()) do
player_stats[stat.Name] = stat.Value
end
return player_stats
end
local function onPlayerExit(player)
local player_stats = create_table(player)
local success, err = pcall(function()
local playerUserId = "Player_" .. player.UserId
playerData:SetAsync(playerUserId, player_stats)
end)
if not success then
warn('Could not save data!')
end
end
game.Players.PlayerAdded:Connect(onPlayerJoin)
game.Players.PlayerRemoving:Connect(onPlayerExit)
Then make a part, add a script, and put this. To get the subgames id, go to asset manager, right click on the place, and copy id to clipboard.
local Part = script.Parent
local TeleportService = game:GetService("TeleportService")
local placeId = 8571558596 -- change this to place id
local function changePlace(otherPart)
local humanoid = otherPart.Parent:FindFirstChild("Humanoid")
if humanoid then
local player = game.Players:GetPlayerFromCharacter(otherPart.Parent)
local playerStats = player:WaitForChild('PlayerStats')
local Coins = playerStats:WaitForChild('Coins')
local AmountOfCoins = Coins.Value
if player then
local data = {}
data["coins"] = AmountOfCoins
TeleportService:Teleport(placeId, player, data)
end
end
end
Part.Touched:Connect(changePlace)
Then make a ScreenGui, TextLabel, and put a local script in the TextLabel. This goes in your subgame Obby.
local TeleportService = game:GetService("TeleportService")
local data = TeleportService:GetLocalPlayerTeleportData()
local Label = script.Parent
if data then
local coins = data["coins"]
Label.Text = coins
else
Label.Text = "No Data"
end
If you want to change the players coins then just put a part into studio, then put a ClickDetector and script into it.
local function GetCash(plr)
plr.PlayerStats.Coins.Value += 5
end
script.Parent.ClickDetector.MouseClick:Connect(GetCash)
Ok, now publish the game. Go to the game on the create tab, click configure experience then places, then Main Game. Finally play the game and it will work!!!