So basically i'm making a script that when you fall off the map and touch it, it gives you 1 "Deaths" leaderstat. But, it isn't working. Here is my code:

local part = script.Parent

local canGet = true



local function onTouch(otherPart)

	local humanoid = otherPart.Parent:FindFirstChild('Humanoid')

	if humanoid then

		local player = game.Players:FindFirstChild(otherPart.Parent.Name)

		if player and canGet then

			canGet = false

			player.leaderstats.Deaths.Value = player.leaderstats.Deaths.Value + 1 
			function onTouch(part)
				if part.Parent.Humanoid ~=nil then
					part.Parent:MoveTo(script.Parent.Parent.Parent.Parent.GoBack1.Position)
					script.Parent.Parent.Parent.Parent.GoBack1.Script.Disabled = true 
					wait(2)
					script.Parent.Parent.Parent.Parent.GoBack1.Script.Disabled = false
				end
			end
			script.Parent.Touched:connect(onTouch)		

			wait(60)

			canGet = true

		end

	end

end



part.Touched:Connect(onTouch)

Thank You.

3 comments

0

Why dont do it when a player dies?

0

I'm making an obby/parkour game and don't want the player to fall for a while and reset.

0

you can just make a that barrier thing kill on touch, and when the player dies, it adds the deaths value