I am basically trying to make a system that randomly sets respawn points. (Like a random check point obby) I want to make it so that if you die, you respawn at your most recent random checkpoint.
Probably too much for 1 post, but I want to also have a system that lets you go back checkpoints if you have a problematic respawn spot that kills you.
I currently have this:
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Humanoid = Character.Humanoid
local VectorZero = Vector3.new(0, 0, 0)
local moving = false
local function Moved()
if Humanoid.MoveDirection ~= VectorZero then
Humanoid.WalkSpeed = 25
moving = true
else
print("Stopped Moving")
moving = false
end
end
Humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(Moved)
if moving == false then
math.random(1,25)
if math = 10 then
end
end
(im aware that line 23 is incomplete)
Things im having issues with:
No idea how to get the player’s position
Getting a random error that I cant figure out at line 22
I really have no idea how to make them respawn at this random point.
Sure, I’d be happy to help! To address your first issue, you can get a player’s position using the Character object’s Position property. For example, to get the LocalPlayer’s position, you would use local pos = Character.Position.
As for the second issue, the error you’re getting is likely because of the equality comparison on line 22. You should use the == operator to check for equality instead of =, which is an assignment operator. So your code should be:
if math.random(1, 25) == 10 then
end
Finally, to make the player respawn at the checkpoint, you can use the HumanoidRootPart property’s CFrame property to set the respawn location. For example, to set the player’s respawn location to a Vector3 position checkpointPos, you would use HumanoidRootPart.CFrame = CFrame.new(checkpointPos).