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 9 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)

01if hit.Parent:FindFirstChild("Humanoid") ~= nil then
02 
03    if game.Players:FindFirstChild(hit.Parent.Name) ~= nil then
04    local player = game.Players:FindFirstChild(hit.Parent.Name)
05 
06        if player:FindFirstChild("PlayerGui"):FindFirstChild("ScreenGui") == nil then
07        sg = Instance.new("ScreenGui")
08        sg.Parent = player:FindFirstChild("PlayerGui")
09        end
10 
11    if player.PlayerGui.ScreenGui:FindFirstChild("MessageBox") == nil then
12 
13    local f = Instance.new("Frame")
14    f.Name = "MessageBox"
15    f.Position = UDim2.new(0.3, 0, 0.88, 0)
View all 25 lines...

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


1    f:Destroy()
2    end
3    end
4end

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 — 9y
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 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

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

01--by krisxxxz
02debounce = false
03function onTouched(hit)
04    local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
05    plr.PlayerGui.ScreenGui.TextBox.Visible = true
06end
07function touchEnd(hitend)
08    local plrend = game.Players:GetPlayerFromCharacter(hitend.Parent)
09    plrend.PlayerGui.ScreenGui.TextBox.Visible = false
10end
11script.Parent.Touched:connect(onTouched)
12script.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

01--by krisxxxz
02enabled = true
03function onTouched(hit)
04        if enabled then
05    local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
06    plr.PlayerGui.ScreenGui.TextBox.Visible = true
07end
08end
09function touchEnd(hitend)
10        enabled = false
11    local plrend = game.Players:GetPlayerFromCharacter(hitend.Parent)
12    plrend.PlayerGui.ScreenGui.TextBox.Visible = false
13        wait(2) --How long you want player to read it again
14        enabled = true
15end
16script.Parent.Touched:connect(onTouched)
17script.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 — 9y
0
ah you will need some variables of course. I'll edit it when I have time... Im in hurry. krisxxxz 45 — 9y
Ad

Answer this question