hey all. meh hitting this error:
Error lines:
ObbySavingSystem line 11 (line number of the code below)
if ply.leaderstats.Stage.Value < tonumber(part.Name) then
Leaderboard line 23 (line number of the code below)
if (Leaderstats and Leaderstats.Stage) then
|
--ObbySavingSystem script
local DataStoreService = game:GetService("DataStoreService")
local StageDataStore = DataStoreService:GetDataStore("StageData")
local Stage = script.Parent:WaitForChild("Leaderboard")
--local Stage = script.Parent:WaitForChild("Leaderboard")
--Stage:Leaderboard()
local function TouchedPart(part, touchedPart)
local ply = game.Players:GetPlayerFromCharacter(touchedPart.Parent)
if ply then
if ply.leaderstats.Stage.Value < tonumber(part.Name) then
ply.leaderstats.Stage.Value = tonumber(part.Name)
end
end
end
local function AddTouchStageGiver()
local stageNum = 0
while true do
local part = game.Workspace:FindFirstChild(tostring(stageNum))
if part then
part.Touched:connect(function (touchedPart)
TouchedPart(part, touchedPart)
end)
else
break
end
stageNum = stageNum + 1
wait()
end
end
local function GetSavedStage(ply)
return StageDataStore:GetAsync(tostring(ply.UserId)) or 0
end
local function SaveCurrentStage(ply)
StageDataStore:SetAsync(tostring(ply.UserId), ply.leaderstats.Stage.Value)
end
local SPAWN_OFFSET = Vector3.new(0, 5, 0)
local function GetStageSpawnCFrames(stage)
local stageSpawnPart = game.Workspace:FindFirstChild(tostring(stage))
if not stageSpawnPart then
return game.Workspace:FindFirstChild("0").CFrame + SPAWN_OFFSET
end
return stageSpawnPart.CFrame + SPAWN_OFFSET
end
local stageValues = {}
local function CharacterAdded(ply, char)
repeat wait() until stageValues[ply]
char:SetPrimaryPartCFrame(GetStageSpawnCFrames(stageValues[ply].Value))
end
game.Players.PlayerAdded:connect(function (ply)
local leaderstats = Instance.new("ObjectValue", ply)
leaderstats.Name = "leaderstats"
ply.CharacterAdded:connect(function (char)
CharacterAdded(ply, char)
end)
local stage = Instance.new("IntValue", leaderstats)
stage.Name = "Stage"
stage.Value = GetSavedStage(ply)
stageValues[ply] = stage
--[[
if ply.Character then
CharacterAdded(ply, ply.Character)
end
--]]
end)
game.Players.PlayerRemoving:connect(function (ply)
SaveCurrentStage(ply)
end)
wait(0.3)
AddTouchStageGiver()
--Leaderboard script
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local StageDataStore = DataStoreService:GetDataStore("StageData")
local Stage = script.Parent:WaitForChild("Leaderboard")
Players.PlayerAdded:Connect(function(Player)
local Leaderstats = Instance.new("Folder")
Leaderstats.Name = "leaderstats"
Leaderstats.Parent = Player
local Stage = Instance.new("IntValue")
Stage.Name = "Stage"
Stage.Value = 0
local function SaveCurrentStage(ply)
Stage.Value = StageDataStore:SetAsync(tostring(ply.UserId), ply.leaderstats.Stage.Value)
Stage.Value = 0
Stage.Parent = Leaderstats
end -- End for the function
Player.CharacterAdded:Connect(function(Characer)
local Leaderstats = Player:FindFirstChild("leaderstats")
if (Leaderstats and Leaderstats.Stage) then
local Stage = workspace:FindFirstChild(tostring(Stage.Value))
if (Stage) then
Player.Character:MoveTo(Stage.Position + Vector3.new(0,3,0))
end
end
end) -- End) for the CharacterAdded function
end)
thanks to those who are not indifferent :)

2 comments
Which line is it coming from?
ok