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)
01 | if 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 = UDim 2. new( 0.3 , 0 , 0.88 , 0 ) |
m.Text = "text would be placed here" wait(5)
1 | f:Destroy() |
2 | end |
3 | end |
4 | end |
end
script.Parent.Touched:connect(onTouch)
Well, you can just do TouchEnded if you want. I hope this is what you mean so.. Heres my way:
01 | --by krisxxxz |
02 | debounce = false |
03 | function onTouched(hit) |
04 | local plr = game.Players:GetPlayerFromCharacter(hit.Parent) |
05 | plr.PlayerGui.ScreenGui.TextBox.Visible = true |
06 | end |
07 | function touchEnd(hitend) |
08 | local plrend = game.Players:GetPlayerFromCharacter(hitend.Parent) |
09 | plrend.PlayerGui.ScreenGui.TextBox.Visible = false |
10 | end |
11 | script.Parent.Touched:connect(onTouched) |
12 | 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
01 | --by krisxxxz |
02 | enabled = true |
03 | function onTouched(hit) |
04 | if enabled then |
05 | local plr = game.Players:GetPlayerFromCharacter(hit.Parent) |
06 | plr.PlayerGui.ScreenGui.TextBox.Visible = true |
07 | end |
08 | end |
09 | function 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 |
15 | end |
16 | script.Parent.Touched:connect(onTouched) |
17 | 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.