The script did work for a while, but now for some reason it does not work anymore.
Any reasons why?
Here’s the code:
local DataStoreService = game:GetService("DataStoreService")
local playerData = DataStoreService:GetDataStore("PlayerData")
local function onPlayerJoin(Player)
local BlackMarketThings = Instance.new("Folder")
BlackMarketThings.Name = "BlackMarketThings"
BlackMarketThings.Parent = Player
local SpeedCheck = Instance.new("BoolValue")
SpeedCheck.Name = "SpeedCheck"
SpeedCheck.Parent = BlackMarketThings
SpeedCheck.Value = false
local playerUserId = "Player_ ".. Player.UserId
local data = playerData:GetAsync(playerUserId)
if data then
SpeedCheck.Value = data and data.SpeedCheck
else
SpeedCheck.Value = false
end
end
local function onPlayerLeave(Player)
local success, err = pcall(function()
local playerUserId = "Player_ "..Player.UserId
local speedCheckValue = Player.BlackMarketThings.SpeedCheck.Value
local dataToSave = {
SpeedCheck = speedCheckValue
}
playerData:SetAsync(playerUserId, dataToSave)
end)
if not success then
warn("Could not save data, Error message: ", err)
else
print("Saved 2")
end
end
game.Players.PlayerAdded:Connect(onPlayerJoin)
game.Players.PlayerRemoving:Connect(onPlayerLeave)