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)
No, since doing data and before assigning it makes sure the data exists before trying to get any attributes. If the player’s data was nil, SpeedCheck.Value = data.SpeedCheck would give an error, stating that it cant find missing attribute SpeedCheck of nil
With the addition, if data is nil, it sets SpeedCheck.Value to false instead of giving an error.