I want to reset checkpoints but i dont know how to do it

  1. What do you want to achieve? I want to reset checkpoints

  2. What is the issue? I dont know how to make it

  3. What solutions have you tried so far? I tried whatever i can but im still new at scripting so i couldnt make it

There is my Checkpoint code:

 local Checkpoints = game.Workspace:WaitForChild("Checkpoints")

game.Players.PlayerAdded:Connect(function(plr)
	
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = plr
	
	local v = Instance.new("IntValue")
	v.Name = "Stage"
	v.Value = 1
	v.Parent = leaderstats
	
	plr.CharacterAdded:Connect(function(char)
		
		local hum = char:WaitForChild("Humanoid")
		wait()
		char:MoveTo(Checkpoints[v.Value].Position)
		
		hum.Touched:Connect(function(hit)
			
			if hit.Parent == Checkpoints then
				if tonumber(hit.Name) == v.Value+1 then
					v.Value = v.Value +1
				end
			end
			
		end)
		
	end)
end)

What should i do ? Should i change the checkpoint script or should i use DataStoreService ?

What do you mean by reset checkpoints? Do you want it to go back to 0? If so you can do v.Value = 0 or plr.leaderstats.Stage.Value = 0

I mean 2414141

when this touched event fires i want to reset checkpoints who touched

I still don’t know what you mean by reset? So you want it to go to 0 when they touch the part?

yeah yeah they will go to where they start

-- Client Side
-- Make a Remote Event, so when the touch event is fired it also fires a RemoteEvent

-- Services
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ResetCheckpointEvent = ReplicatedStorage.RemoteEvent 

game.Workspace.Cellatbaba.Hitbox.Touched:Connect(function(hit)
   if Players:GetPlayerFromCharacter(hit.Parent) then
      -- Set Characters health to 0 
      ResetCheckpointEvent:FireServer()
   end
end)

Now on the server you can do

-- Server Script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ResetCheckpointEvent = ReplicatedStorage.RemoteEvent 

ResetCheckpointEvent .OnServerEvent:Connect(function(player)
   player.leaderstats.Stages.Value = 0
end

You’re attempting to find the leaderstats already with game.Players:WaitForChild("leaderstats", 1) without implementing a check inside your Touched event

What I’d do is create a Player variable inside your Touched event, check if the Player & leaderstats are valid, then just reset back their stats to 0:

local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
if Player then
    hit.Parent.Humanoid.Health = 0
    workspace.CellatBaba:SetPrimaryPartCFrame(CFrame.new(0, 0, 0))
    local leaderstats = Player:WaitForChild("leaderstats", 1)
    if leaderstats then
        leaderstats.Stage.Value = 0
    end
end

Allright im gonna test right now

No need for a RemoteEvent, you can get the player’s stats by using Hit.Parent easily inside the Touched event

oh okey i will test this tooooo

Oh right, I always make changes to the players data on the server, but in this case I don’t think you really need to use a RemoteEvent. Either way should work fine.

So i put this code in touched event

hit.Parent.leaderstats.Stage.Value = 1	

it didnt work and i have this errorunknowrsfasfasfafafafan

Btw i didnt do your first reply

The Character doesn’t have the leaderstats, you have to get the Player using the GetPlayerFromCharacter function

Can you explain a little bit how to do ?

The function literally is what it says: Gets the Player Object from the Character Model that hit the part

If I were to put this:

local Player = game.Players:GetPlayerFromCharacter(hit.Parent)

hit is referring to the actual part name that it hit, but we don’t want that (Right Arm, Left Leg, etc)

Instead, we use hit.Parent to get the HitPart’s parent (Or in this instance, the Character’s Model)

That way, we’ll be able to access both the Player & Character just from using a Touched event but we wanna change the leaderstats so we use Player.leaderstats.Stage.Value = 0 instead

1 Like

Okey i get it thank you for being patient to me xd

Now we can change the Value of Stages but even if i changed to number im still spawning at last checkpoint that i touched

If I want to reset checkpoints, all I do is change the name of the datastores.

I’m not a pro of scripting, this is all the help I can give.

Thank you for answer, i think we solved the problem but we have another problem even if i change the stages it doesnt change the spawnpoint. Should i create another topic for that problem ?

Probably. Happy I (kinda) helped!

I cant send small massages dude what is that all i want to say just " Yeah xd"