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