Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I correct the timer in this surfacegui?

Asked by 3 years ago
Edited 3 years ago

I´m reading the script fundamentals material from the roblox education page https://education.roblox.com/en-us/resources/intro-to-coding-coding-3-multiple-conditions-with-if-elseif-and-else ... The lecture (if this can be considered as one), tells me to make a finish line part and some optional challenges. One of them is to make a part that resets the time of the run, the other one is about a surfacegui where I´m told to print the current time of the run, until the end. Also there´s a reamining challenge with tables, but, since I don´t know how to use them yet, I´ve skipped it by now.

this code is what I´ve came up to do the 1st and 2nd challenges:

local endpart=script.Parent
racetime=0
local display= game.Workspace.displayInformation
local textzone=display.SurfaceGui.TextLabel
local startpart=game.Workspace.start

local function start(anypart)
    local chara=anypart.Parent
    local  human= chara:FindFirstChildWhichIsA("Humanoid")
    if human then
        raceActive=true
        while raceActive==true do
            wait(1)
            racetime=racetime+1
            print(racetime)
            textzone.Text=racetime

        end
    end
end 
local function finish()
    print("part is being touched")
    raceActive=false
    if racetime<=30 then
        textzone.Text="gold"
    elseif racetime>30 and racetime<=40 then
        textzone.Text="silver"
    elseif racetime>40 and racetime<=45 then 
        textzone.Text="bronze"
    else 
        textzone.Text="try again"
    end
    racetime=0

end
local function finished(anypart)
    local chara=anypart.Parent
    local human=chara:FindFirstChildWhichIsA("Humanoid")
    if human and raceActive==true then
        finish()
    end
end
startpart.Touched:Connect(start)
endpart.Touched:Connect(finished)

I have a problem when touching the startpart, it seems like its printing the next 4 seconds" each second

Btw. If you find a grammar mistake,word misspelling or another comunicative issue write me the correction pls :p. Ty for reading!!

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

I had made another function to trigger the RaceActive boolean to be true... If it is helpful to anyone...

local endpart=script.Parent
racetime=0
local display= game.Workspace.displayInformation
local textzone=display.SurfaceGui.TextLabel
local startpart=game.Workspace.start
--start display
local function start(anypart)
    local chara=anypart.Parent
    local  human= chara:FindFirstChildWhichIsA("Humanoid")
    if human then
        while raceActive==true do
            racetime=racetime+1
            textzone.Text=racetime
            wait(1)
        end
    end
end 

local function finished(anypart)
    local chara=anypart.Parent
    local human=chara:FindFirstChildWhichIsA("Humanoid")
    if human and raceActive==true then
        print("part is being touched")
        raceActive=false
        if racetime<=30 then
            textzone.Text="gold"
        elseif racetime>30 and racetime<=40 then
            textzone.Text="silver"
        elseif racetime>40 and racetime<=45 then 
            textzone.Text="bronze"
        else 
            textzone.Text="try again"
        end
        racetime=0
    end
end
local function trigger(any)
    local part=any.Parent
    local human=part:FindFirstChildWhichIsA("Humanoid")
    if human then
        raceActive=true
    end
end
startpart.Touched:Connect(trigger)
startpart.Touched:Connect(start)
endpart.Touched:Connect(finished)

Although, I don´t know why works properly in this way

Ad

Answer this question