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

OnTouch player timer GUI?

Asked by
steev 0
10 years ago

When the player touches a brick a GUI timer pops up with 30 seconds.

When the timer runs out the player gets killed and the timer resets back to 30 seconds

I want the timer to pop up when the player actually touches the brick.

Can anyone make up a Lua script for this?

1 answer

Log in to vote
0
Answered by 10 years ago

I use the Touched event of a brick to know when it is touched. Then I check to make sure the part that touched it is part of a character. And if they don't have the GUI I give it to them and start the countdown.

function NewGui()
    local Gui = Instance.new("ScreenGui")
    Gui.Name = "Countdown Gui"
    local Tect = Instance.new("TextLabel",Gui)
    Text.Name = "Countdown"
    Text.Size = UDim2.new(0.3,0,0.3,0) --Adjust size 
    Text.Position = UDim2.new(0,0,0,0) --Adjust position if wanted.
    return Gui
end
script.Parent.Touched:connect(function(Part)
    local Player = Game:GetService("Players"):GetPlayerFromCharacter(Part.Parent)
    if Player and not Player.PlayerGui:FindFirstChild("Countdown Gui") then
        local Gui = NewGui()
        Gui.Parent = Player.PlayerGui
        for i=30,0,-1 do
            Gui.Countdown.Text = i
            wait(1)
        end
        Player.Character:BreakJoints()
    end
end)
0
Do you put the script into the brick that will be touched? Also do i have to make the Gui or does the script make it for me? steev 0 — 10y
Ad

Answer this question