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)

2 comments
Do you want it to remove after the player is no longer touching that part of after they touch a single different part?
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?