What want to achieve
I want to achieve stopwatch for obby that will turn on when you cross the red line(you can see it on video) and you can turn on it again if you fall.
Issue
One of my best attempts is this. Code that i use:
game.Workspace.Stage1.TimerStart.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
game.Workspace.Stage1.TimerStart.Position = Vector3.new(500,500,500)
--TimerStart is a part that you need to cross to activate stopwatch
--when you fall TimerStart position is going to be normal and player can activate it again
local start = tick()
print(3)
while true do
wait()
if game.Workspace.Stage1.TimerStart.Position == Vector3.new(500,500,500) then
local diff = tick() - start
local min = math.floor(diff / 60)
local sec = diff - min*60
local mil = math.floor((sec - math.floor(sec)) * 10)
sec = math.floor(sec)
print(min, sec, mil)
script.Parent.TextLabel.Text = min..":"..sec..":"..mil
if game.Workspace.Stage1.TimerStart.Position == Vector3.new(500,500,500) then
print(min, sec, mil)
script.Parent.TextLabel.Text = min..":"..sec..":"..mil
end
end
end
end
end)
game.Workspace.Stage1.TimerStart.TouchEnded:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
game.Workspace.Stage1.TimerStart.Position = Vector3.new(500,500,500)
end
end)
Issue is that stopwatch for first time use works great but when you activate it again it starts to write two numbers: one from old use and one from new use at the same time. And maybe another issue that can mess with script that character touches part too many times (like 3-5 times when c rossing it(i redused part size to minimal and still this problem)) but i dont think that it causes an issue(sometimes i get 1 part touch, sometimes i got 7 part touches and script works good for first time use in both situations)