I’ve been having problems with something I’ve been trying to make, everything was going fine but now I don’t know what’s wrong. I’m just trying to create it where when a player touches a part a timer will appear at the top of there screen only for that local player.
When one player touches the part for the first time works -
But when the player touches it for the second time the timer goes into the negatives when its supposed to just reset again and again on each interaction with the part -
Here is the script that I am using -
local minutes = 1
local seconds = 0
local function End(clonedgui)
repeat
if seconds <= 0 then
minutes = minutes - 1
seconds = 59
else
seconds = seconds - 1
end
if seconds < 10 then
clonedgui.TextLabel.Text = tostring(minutes)..":0"..tostring(seconds)
else
clonedgui.TextLabel.Text = tostring(minutes)..":"..tostring(seconds)
end
wait(1)
until minutes <= 0 and seconds <= 0
if minutes <=0 and seconds <=0 then
clonedgui:Destroy()
end
end
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr then
if not plr.PlayerGui:FindFirstChild("GUIClonedfromtouchblock") then
local clonedgui = script.Parent:FindFirstChildOfClass("ScreenGui"):Clone()
clonedgui.Name = "GUIClonedfromtouchblock"
clonedgui.Parent = plr.PlayerGui
End(clonedgui)
script.Parent.TouchEnded:Connect(function(hit2)
if hit == hit2 then
game.Debris:AddItem(clonedgui,0)
end
end)
end
end
end
end)
I think the problem is the second the the player touches the part, the timer doesn’t reset but I’m not sure how to fix this. Thanks.