Hello, @robuxgeng1000.
Errors are definitely a common issue. To help you get started, we can first tackle the leaderstats.
Here is a basic leaderstats script that you can find almost anywhere on the internet:
Server script, should be placed in ServerScriptService
:
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local level = Instance.new("IntValue")
level.Name = "Level"
level.Value = 1 -- Starting level
level.Parent = leaderstats
end)
That manages the playerâs level, and shows it in the leaderstats. If you want level saving, there are too many tutorials out there that show how to connect leaderstats to datastores or other methods of data saving.
To access the data from the player, all we need to do is add a few more lines.
Inside of the PlayerAdded function, at the bottom add:
local playerLevel = player.leaderstats.Level.Value
Then, we can manage the spawning of the player on a part.
Name the part to the desired level number, then add it to our script:
local part = game.Workspace:FindFirstChild(playerLevel)
player.CharacterAdded:Connect(function(char)
char.HumanoidRootPart.CFrame = part.CFrame
end)
Ensure that the part is not a model, but simply a part, otherwise part.CFrame
wonât work. If your âpartâ is a model, then set a PrimaryPart
for your model, and change the above part.CFrame
to part.PrimaryPart.CFrame
With that done, now all we have to do is manage when the player dies, and where to respawn them at.
in our script, create a new function inside of the CharacterAdded function:
char.Humanoid.Died:Connect(function()
char.HumanoidRootPart.CFrame = part.CFrame
end)
This will respawn the player on the part, based on the partâs name and the playerâs level
The full script:
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local level = Instance.new("IntValue")
level.Name = "Level"
level.Value = 1 -- Starting level
level.Parent = leaderstats
local playerLevel = player.leaderstats.Level.Value
local part = game.Workspace:FindFirstChild(playerLevel)
player.CharacterAdded:Connect(function(char)
char.HumanoidRootPart.CFrame = part.CFrame
char.Humanoid.Died:Connect(function()
char.HumanoidRootPart.CFrame = part.CFrame
end)
end)
end)
Let me know if you have any other questions.