I want to make a value bool inside the player and then check if it is true or false to check if he has already played the game, if he has already played he will be teleported to the second part of the game but I am having problems, can anyone help me?
I've tried it a few times...
But none of them worked
The Scripts I've tried:
local DSService = game:GetService('DataStoreService'):GetDataStore('JaJoguei')
game.Players.PlayerAdded:connect(function(plr)
-- Define variables
local uniquekey = 'id-'..plr.userId
local savevalue = Instance.new('IntValue', plr)
savevalue.Name = 'JaJoguei'
-- GetAsync
local GetSaved = DSService:GetAsync(uniquekey)
if GetSaved then
savevalue.Value = GetSaved
else
local NumbersForSaving = {savevalue.Value}
DSService:SetAsync(uniquekey, NumbersForSaving)
end
end)
game.Players.PlayerRemoving:connect(function(plr)
local uniquekey = 'id-'..plr.userId
local Savetable = {plr.leaderstats.Cash.Value}
DSService:SetAsync(uniquekey, Savetable)
end)
local DataStore = game:GetService("DataStoreService"):GetDataStore("JaJogou")
game.Players.PlayerAdded:connect(function(plr)
local JJG = Instance.new("BoolValue", plr)
JJG.Value = false
local key = "user-" .. plr.userId
local DataSaved = DataStore:GetAsync(key)
if DataSaved then
local JJGSaved = JJG.Value
else
local ValorPraSalvar = (JJG.Value)
DataStore:SetAsync(key, ValorPraSalvar)
end
end)
local module = {}
local Storage = game:GetService("DataStoreService"):GetDataStore("Test")
game.Players.PlayerAdded:connect(function(plr)
JaJogou = Instance.new("BoolValue", plr)
JaJogou.Name = "Ja_Jogou"
local Save = Storage:GetAsync(plr.userId .. "-JaJogou")
if Save ~= nil then
JaJogou.Value = Save
end
end)
game.Players.PlayerRemoving:connect(function(plr)
local id = plr.userId
local Salvo = JaJogou.Value
Storage:SetAsync(id .. "-JaJogou", Salvo)
end)
return module
local DS = game:GetService("DataStoreService"):GetDataStore("Teste")
local Play = game.ServerStorage.Play
game.Players.PlayerAdded:connect(function(player)
local Ja_Jogou = Instance.new("BoolValue")
Ja_Jogou.Parent = game.ServerStorage:WaitForChild("Player1")
Play.Name = player.Name
local SavedStuff = DS:GetAsync(player.userId)
if SavedStuff then
print("data takes up ".. game:GetService("HttpService"):JSONEncode(SavedStuff):len() .. "/260000")
for i,v in pairs(SavedStuff) do
print(i,v)
if i % 2 == 0 then
Play[player.Name]:FindFirstChild(SavedStuff[i - 1]).Value = v
end
end
end
end)
local function SaveValue(player)
local SavedData = {}
for i,v in pairs(Play[player.Name]:GetChildren()) do
SavedData[#SavedData +1] = v.Name
SavedData[#SavedData +1] = v.Value
end
DS:SetAsync(player.userId, SavedData)
end
game:BindToClose(function()
for i,player in pairs(game.Players:GetPlayers()) do
SaveValue(player)
end
end)
game.Players.PlayerRemoving:connect(function(Player)
SaveValue(Player)
end)
game.Players.PlayerAdded:connect(function()
local Player1 = game.ServerStorage:WaitForChild("Player1")
if Player1.Ja_Jogou.Value == true then
local GameId = 491387737
game:GetService("TeleportService"):Teleport(GameId)
print("Teleportando")
end
end)

1 comment
Can you show us what you have already tried?