How can i Reset the Checkpoint?

  1. What do you want to achieve? Whenever the touched event fires whoever touched his checkpoints will be resets

  2. What is the issue? I can change the value of checkpoint but it doesnt work

  3. What solutions have you tried so far? I couldnt find anything

Here is my codes:

game.Players.PlayerAdded:Connect(function(Player)
	local leaderstats = Instance.new("Folder", Player)
	leaderstats.Name = "leaderstats"
	
	local Checkpoint = Instance.new("IntValue", leaderstats)
	Checkpoint.Name = "Checkpoint"
	Checkpoint.Value = 1
	
	Player.CharacterAdded:Connect(function(Character)
		repeat wait() until Player.Character ~= nil
		local checkpoint = game.Workspace.Checkpoints:FindFirstChild(Checkpoint.Value)
		Character:WaitForChild("HumanoidRootPart").CFrame = CFrame.new(checkpoint.Position + Vector3.new(0,2,0))
	end)
	
end)
local Checkpoints = script.Parent


for i,v in pairs(Checkpoints:GetChildren()) do
	if v:IsA("BasePart") then
		v.Touched:Connect(function(hit)
			if hit.Parent:FindFirstChild("HumanoidRootPart") then
				local player = game.Players:GetPlayerFromCharacter(hit.Parent)
				if player then
					if player.leaderstats.Checkpoint.Value < tonumber(v.Name) then
						player.leaderstats.Checkpoint.Value = tonumber(v.Name)
					end	
				end	
			end	
		end)	
	end
end

So basically i can change the value but it dosent work, in leaderboard im in Checkpoint 1 but in game im in Checkpoint 4, how can i fix that

4 Likes

Make sure you are handling the second script via server-sided Script. It makes no sense if you are using LocalScripts to do it because LocalScripts will only work for the player’s client. The leaderboard you are using for showing players’ leader stats won’t update the checkpoint value because it is just for the client, it is only for you. But if you do it in a server-sided script, it will also update and save your value.

So this script must be executed via server. Put this script in ServerScriptService.

for i, v in pairs (game.Workspace.Checkpoints:GetChildren()) do
    v.Touched:Connect(function(hit)
	    local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
	    local CheckpointValue = player:WaitForChild("leaderstats").Checkpoint.Value
	
	    if player then
		    if CheckpointValue + 1 == tonumber(v.Name) then
			    CheckpointValue = tonumber(v.Name)
		    end	
	    end
    end)
end

Yeah 2 of the scripts are server side

SpawnPointScript is First Script
TouchHandler is Second Script

Delete TouchHandler script which is in the Checkpoints folder and insert a new script in ServerScriptService. Paste this script into it.

Checkpoints klasörünün içindeki TouchHandler’ı sil ve ServerScriptService'e bir kod bloğu açıp bu kodu onun içine yerleştir.

Tutorial1

for i, v in pairs (game.Workspace.Checkpoints:GetChildren()) do
	if v:IsA("BasePart") then
		v.Touched:Connect(function(hit)
			
			local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
			
			if player then
				if (tonumber(Checkpoint.Value + 1)) == tonumber(v.Name) then
					Checkpoint.Value = tonumber(v.Name)
				end
			else
				return false
			end
		end)
	end
end

Well i disabled TouchHandler and i insert a new Script in a ServerScriptService,


and copy paste this code and i launched and we have and error says:image

game.Players.PlayerAdded:Connect(function(player)
    local leaderstats = Instance.new("Folder", player)
    leaderstats.Name = "leaderstats"

    local Checkpoint = Instance.new("IntValue", leaderstats)
    Checkpoint.Name = "Checkpoint"
    Checkpoint.Value = 1

    repeat
	    wait()
    until player.CharacterAdded

    for i, v in pairs (game.Workspace.Checkpoints:GetChildren()) do
	    if v:IsA("BasePart") then
		    v.Touched:Connect(function(hit)
			
			    local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
			
			    if player then
				    if (tonumber(Checkpoint.Value + 1)) == tonumber(v.Name) then
					    Checkpoint.Value = tonumber(v.Name)
				    end
			    else
				    return false
			    end
		    end)
	    end
    end
end)

Okay try this one and don’t define any variable. It’ll work now.

Bunu SpawnPointScript’e koy çünkü az önce kendime göre yapmıştım. :sweat_smile: O yüzden çalışmamış olabilir. local Checkpoint yazmışsın. Oradaki kastım Checkpoints klasörü değildi, oyuncunun klasöründeki değerdi. O yüzden checkpoint diye bir değişken atadığın için çalışmadı. Şimdi buna hiçbir şey yazmadan koyabilirsin. Eminim şimdi çalışacaktır.

Should i delete everything inside in SpawnPointScript ?

Eğer SpawnPointScript’in içindeki sadece yukarıdaki gibiyse onu silip aşağıdakini ekle.

game.Players.PlayerAdded:Connect(function(player)
    local leaderstats = Instance.new("Folder", player)
    leaderstats.Name = "leaderstats"

    local Checkpoint = Instance.new("IntValue", leaderstats)
    Checkpoint.Name = "Checkpoint"
    Checkpoint.Value = 1

    repeat
        wait()
    until player.CharacterAdded

    player.CharacterAdded:Connect(function(Character)
	    repeat wait() until player.Character ~= nil
	    local checkpoint = game.Workspace.Checkpoints:FindFirstChild(Checkpoint.Value)
	    Character:WaitForChild("HumanoidRootPart").CFrame = CFrame.new(checkpoint.Position + Vector3.new(0,2,0))
    end)

    for i, v in pairs (game.Workspace.Checkpoints:GetChildren()) do
        if v:IsA("BasePart") then
	        v.Touched:Connect(function(hit)
		
		        local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
		
		        if player then
			        if (tonumber(Checkpoint.Value + 1)) == tonumber(v.Name) then
				        Checkpoint.Value = tonumber(v.Name)
			        end
		        else
			        return false
		        end
	        end)
        end
    end
end)

It doesnt work either, i recorded some vids you can see what happens and i cant

Okey im uploading to youtube so you can see whats the problem

Here you go.

No no no thats not what im talking about, its just checkpoint i want to make if spesific event fires and resets checkpoint who touched this event

game.Players.PlayerAdded:Connect(function(player)
    local leaderstats = Instance.new("Folder", player)
    leaderstats.Name = "leaderstats"

    local Checkpoint = Instance.new("IntValue", leaderstats)
    Checkpoint.Name = "Checkpoint"
    Checkpoint.Value = 1

    repeat
        wait()
    until player.CharacterAdded
    
    local part = game.Workspace.Part

    part.Touched:Connect(function(hit)

        local checkPlayer = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
        if checkPlayer then
            Checkpoint.Value = 0
        end
    end)
end)

Finally i uploaded the video

What is the Part i dont get it

I think you are using a script under the part because when I checked in the studio there was no problem. I think you should check if there is a Script under the part. It must have affected your value.

Can you explain a little bit because i dont understand, in your video its just Checkpoint, i want to reset the checkpoint

CellatBaba modelinin altında kod bloğu olabilir mi? Değeri 0 yapan bir kod olmalı. Böyle bir kod olabilir mi?

script.Parent.Touched:Connect(function()
    player.leaderstats.Checkpoint.Value = 0
end)

Böyle bir şey varsa sil.

No i made CellatBaba xd from 0 animation face clothing all of these stuff. So Cellat doesnt have any code like that, but i have this code in my other script