Hello, i am a beginner scripter in roblox studio, but im learning new things really fast.
I had that one error in Roblox Studio where i was making a data store in my game (The Ultimate Elevator) and i kept getting an error like this:
I really don’t know how to fix it, i even tried converting the value to tonumber(), nothing worked and gave me another error, and this is my script i made:
local dss = game:GetService("DataStoreService")
local ds = dss:GetDataStore("ElevatorLevel")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = player:FindFirstChild("hiddenLeaderstats")
local ElevatorLevel = Instance.new("IntValue", leaderstats)
ElevatorLevel.Name = "ElevatorLevel"
ElevatorLevel.Value = 1
local data
local success, errormessage = pcall(function()
data = ds:GetAsync(player.UserId.."-ElevatorLevel")
end)
if success then
ElevatorLevel.Value = data -- This is the line where the error appeared.
else
warn(errormessage)
print("error loading data")
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, errormessage = pcall(function()
ds:SetAsync(player.UserId.."-ElevatorLevel", player:WaitForChild("hiddenLeaderstats").ElevatorLevel.Value)
end)
if success then
print("player data saved.")
else
print("failed to save data")
warn(errormessage)
end
end)