How would I create a lap system?

I am making a game like fly race and I need help, I need to teleport the player when they reach a block called TpEnd to the start but it doesn’t work!

script.Parent.Parent.CountdownWall:Destroy()
db = false
script.Parent.Parent.hitPart.Touched:Connect(function(obj)
	if obj.Parent:FindFirstChild("Humanoid") then
		local plr = obj.Parent
		local player = game.Players:FindFirstChild(plr.Name)
		if player then
			script.Parent.Swoosh:Play()
			local stat = player:WaitForChild("leaderstats")
			local power = stat.Power
			if power.Value >= 0 then
				plr.PrimaryPart.Anchored = true
				if power.Value >= 5000 then
					for i = 1, power.Value * 0.083 do
						if db == false then
							wait()
							plr.PrimaryPart.Position += Vector3.new(0,0,12)
							task.wait()
						end
					end
				else
					if power.Value >= 1000 then
						for i = 1, power.Value * 0.14 do
							wait()
							plr.PrimaryPart.Position += Vector3.new(0,0,7)
							task.wait()
						end
					else
						for i = 1, power.Value * 0.5 do
							wait()
							plr.PrimaryPart.Position += Vector3.new(0,0,2)
							task.wait()
						end
					end
				end
				plr.PrimaryPart.Anchored = false
				stat.Money.Value += power.Value
				wait(1)
				plr.Humanoid.Health = 0
			end
		end
	end
end)

script.Parent.Parent.TpStart.Touched:Connect(function(obj)
	if obj.Parent:FindFirstChild("Humanoid") then
		local plr = obj.Parent
		local player = game.Players:FindFirstChild(plr.Name)
		if player then
			plr.PrimaryPart.CFrame = script.Parent.Parent.TpStart.CFrame
		end
	end
end)

Are you talking about a racing game-type system?

1 Like

btw you should put this on #help-and-feedback:scripting-support

1 Like

Sorry must have misclicked
(dshad)

1 Like

yeah like that
bfhdsbfjhsdghgf

script.Parent.Parent.TpEnd.Touched:Connect(function(obj)
if obj.Parent:FindFirstChild(“Humanoid”) then
local plr = obj.Parent
local player = game.Players:FindFirstChild(plr.Name)
if player then
plr.PrimaryPart.CFrame = script.Parent.Parent.TpStart.CFrame
end
end
end)

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.