Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Is there a method to add an wait() onto an if and then as a single function?

For example

if HumanoidIsFound and PlayerIsFound then

I am having troubles understanding the if and then concepts using an wait(). I have read wiki articles as well as Roblox Blogs on the If and then and wait, although I still can not understand how to place all three together in a single function.

The line im working with---

if HumanoidIsFound and PlayerIsFound then
        PlayerIsFound.PlayerGui.ScreenGui.TextButton.Visible = true
    end
end

If necessary to understand what I mean here is the script im working with------

local p = script.Parent


function onTouch(part)
    local HumanoidIsFound = part.Parent:FindFirstChild("Humanoid")
    local PlayerIsFound = game.Players:GetPlayerFromCharacter(part.Parent)
    if HumanoidIsFound and PlayerIsFound then
        PlayerIsFound.PlayerGui.ScreenGui.TextButton.Visible = true
    end
end

p.Touched:connect(onTouch)

1 answer

Never mind I Figured it out lol... Im dumb.

local p = script.Parent


function onTouch(part)
    local HumanoidIsFound = part.Parent:FindFirstChild("Humanoid")
    local PlayerIsFound = game.Players:GetPlayerFromCharacter(part.Parent)
    if HumanoidIsFound and PlayerIsFound then
        PlayerIsFound.PlayerGui.ScreenGui.TextButton.Visible = true
		wait(3)
		PlayerIsFound.PlayerGui.ScreenGui.TextButton.Visible = false
    end
end

p.Touched:connect(onTouch)

1 comment

0

Lol.

This discussion is preserved as it was. New answers, comments, and votes are closed.