I’m creating a spawn location system based on the player’s current leaderstats value. However, when I try configuring the RespawnLocation, I get an error that the property is asking for an object (“Unable to assign property RespawnLocation. Object expected, got CFrame”). I’ve realized by now that it also doesn’t accept CFrames, but how can I give RespawnLocation the player’s current checkpoint given this code?
local leaderstats = Instance.new("Folder")
leaderstats.Parent = player
leaderstats.Name = "leaderstats"
local CurrentCheckpoint = Instance.new("IntValue")
CurrentCheckpoint.Parent = leaderstats
CurrentCheckpoint.Value = 0
CurrentCheckpoint.Name = "Checkpoint"
local obby = workspace.Obby
local checkpoints = obby.Checkpoints
for checkpoint = 1, #checkpoints:GetChildren() do
checkpoints[checkpoint].Touched:Connect(function(touch)
CurrentCheckpoint.Value = checkpoint
local player = game:GetService("Players"):GetPlayerFromCharacter(touch.Parent)
player.RespawnLocation = checkpoints[checkpoint].CFrame -- The line in question
end)
end
end)```
You are trying to assign a normal part as a RespawnLocation
A SpawnLocation is different from a normal part
Instead, teleport the player to the checkpoint when they spawn
(Put this in StarterPlayer > StarterCharacterScripts as a script)
local Players = game:GetService("Players")
local Character = script.Parent
local Player = Players:GetPlayerFromCharacter(Character)
local Checkpoint = workspace.Obby.Checkpoints:FindFirstChild(Player.leaderstats.Checkpoint.Value)
if Checkpoint then
Character:PivotTo(Checkpoint.CFrame)
end
The script above gets their player object from their character
We then get the checkpoint from their leaderstats
If this checkpoint exists, we move the character to that checkpoint
Make sure you remove the player.RespawnLocation assignment line when you put this script in or it will continue to error