I am getting this error. I do I fix it

My error is : [ ServerScriptService.Checkpoints Script:95: Expected ‘end’ (to close ‘function’ at line 7), got ; did you forget to close ‘function’ at line 62?]
code:

local dss = game:GetService("DataStoreService")
local Datastore = dss:GetDataStore("ObbyData")
local checkpoints = workspace.Checkpoints
print("Checkpoints leaderstats working")
print("Deaths leaderstats working")
print("Time leaderstats working")
game.Players.PlayerAdded:Connect(function(plr)
	local obbyData = Datastore:GetAsync(plr.UserId .. "-obbyStageProgress")
	local stats = Instance.new("Folder")
	stats.Name = "leaderstats"
	stats.Parent = plr
	local stage = Instance.new("StringValue")
	stage.Name = "Stage"
	stage.Value = obbyData or 1
	stage.Parent = stats
	local wipeouts = Instance.new("IntValue")
	wipeouts.Name = "Deaths"
	wipeouts.Value = 0
	wipeouts.Parent = stats
	
	local second = Instance.new("IntValue")
	second.Name = "Seconds"
	second.Value = stats
	local file = Datastore:GetAsync(plr.UserId)

if file then
stage.Value = file[1]
		wipeouts.Value = file[2]
	second.Value = file[3]
end
end)
game.Players.PlayerRemoving:Connect(function(player)
Datastore:SetAsync(plr.UserId, {player.leaderstats.Stage.Value, player.Deaths.Value}) -- Change "Money" with your currency.
end)

	local char = plr.Character or plr.CharacterAdded:Wait()
	char:WaitForChild("HumanoidRootPart").CFrame = checkpoints[stage.Value].CFrame
	char.Humanoid.Touched:Connect(function(touch)
		if touch.Parent == checkpoints then 
			if (tonumber(touch.Name)and tonumber(touch.Name)>tonumber(stage.Value))or touch.Name == "End" then
				stage.Value = touch.Name
				pcall(function()
					Datastore:SetAsync(plr.UserId.. "-obbyStageProgress", plr.leaderstats.Stage.Value,plr.leaderstats.Deaths.Value,plr.leaderstats.Seconds.Value)
					
				end)
			end
		end
	end)
	plr.CharacterAdded:Connect(function(char)
		local hrp = char:WaitForChild("HumanoidRootPart")
		local humanoid = char:WaitForChild("Humanoid")
		hrp:GetPropertyChangedSignal("CFrame"):Wait()
		hrp.CFrame = checkpoints[stage.Value].CFrame
			
					
		humanoid.Died:Connect(function(touch)
				wipeouts.Value = wipeouts.Value +1
		
			if touch.Parent == checkpoints then
				if (tonumber(touch.Name)and tonumber(touch.Name)>tonumber(stage.Value))or touch.Name == "End"then
					stage.Value = touch.Name
while true do
						wait(2)
						
						wipeout.Value = wipeout.Value + 1	
					end
					pcall(function()
						
						game.Players.PlayerRemoving:Connect(function(player)
							Datastore:SetAsync(plr.UserId.. "-obbyStageProgress", plr.leaderstats.Stage.Value,plr.leaderstats.Deaths.Value,plr.leaderstats.Seconds.Value)		
						end)
					end)
						
						
					
			
	
				end)
			end)
		end)
	end)
end)
end)

The error means that you’re missing an end somewhere. This is why indenting is important; you can easily fix errors like these by just checking which function doesn’t have an end. Without proper indenting, it’s hard to trace where you’re missing an end.

1 Like