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

Text GUI remove when touched another block?

Asked by 8 years ago

So I have this brick that people touch and see a message on their screen, but I don't know how to remove it as soon as people touch another brick to start reading? Help!

function onTouch(hit)

if hit.Parent:FindFirstChild("Humanoid") ~= nil then

    if game.Players:FindFirstChild(hit.Parent.Name) ~= nil then
    local player = game.Players:FindFirstChild(hit.Parent.Name)

        if player:FindFirstChild("PlayerGui"):FindFirstChild("ScreenGui") == nil then
        sg = Instance.new("ScreenGui")
        sg.Parent = player:FindFirstChild("PlayerGui")
        end

    if player.PlayerGui.ScreenGui:FindFirstChild("MessageBox") == nil then

    local f = Instance.new("Frame")
    f.Name = "MessageBox"
    f.Position = UDim2.new(0.3, 0, 0.88, 0)
    f.Size = UDim2.new(0.4, 0, 0, 50)           
    f.Style = "RobloxRound"                         
    f.Parent = player.PlayerGui:FindFirstChild("ScreenGui")

    local m = Instance.new("TextLabel")
    m.Position = UDim2.new(0.5, 0, 0.5, 0)
    m.Font = "SourceSans"
    m.FontSize = "Size18"                           
    m.TextColor3 = Color3.new(1,1,1)                
    m.Parent = f

m.Text = "text would be placed here" wait(5)


    f:Destroy()
    end
    end
end

end

script.Parent.Touched:connect(onTouch)

0
Do you want it to remove after the player is no longer touching that part of after they touch a single different part? BlackJPI 2658 — 8y
0
Like when they touch the part it would show the message;messages, and if they touch another block it removes the previous message and shows another message, and how do I make it so that the messages have a time limit also? KevinBud2 5 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

Well, you can just do TouchEnded if you want. I hope this is what you mean so.. Heres my way:

--by krisxxxz
debounce = false
function onTouched(hit)
    local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
    plr.PlayerGui.ScreenGui.TextBox.Visible = true
end
function touchEnd(hitend)
    local plrend = game.Players:GetPlayerFromCharacter(hitend.Parent)
    plrend.PlayerGui.ScreenGui.TextBox.Visible = false
end
script.Parent.Touched:connect(onTouched)
script.Parent.TouchEnded:connect(touchEnd)

Notes : I use TextBox. The ScreenGui is the ScreenGui name. The script is inside the touch part. You can remove debounce if you want. Its up to you. Just put the ScreenGui inside StarterGui [My Solution]

If you have any questions then put in the comments.

Edit

--by krisxxxz
enabled = true
function onTouched(hit)
        if enabled then
    local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
    plr.PlayerGui.ScreenGui.TextBox.Visible = true
end
end
function touchEnd(hitend)
        enabled = false
    local plrend = game.Players:GetPlayerFromCharacter(hitend.Parent)
    plrend.PlayerGui.ScreenGui.TextBox.Visible = false
        wait(2) --How long you want player to read it again
        enabled = true
end
script.Parent.Touched:connect(onTouched)
script.Parent.TouchEnded:connect(touchEnd)

Notes : Maybe this will work. I know that debounce is kind of not working anymore so we can use wait if you want. Tell me if that doesn't work I will fix it as fast as possible.

0
How do I make it so that when people touch they read, but they read multiple texts within a few seconds? KevinBud2 5 — 8y
0
ah you will need some variables of course. I'll edit it when I have time... Im in hurry. krisxxxz 45 — 8y
Ad

Answer this question