Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Text GUI remove when touched another block?

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

0

Do you want it to remove after the player is no longer touching that part of after they touch a single different part?

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?

1 answer

✓ Accepted answer

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.

2 comments

0

How do I make it so that when people touch they read, but they read multiple texts within a few seconds?

0

ah you will need some variables of course. I'll edit it when I have time... Im in hurry.

This discussion is preserved as it was. New answers, comments, and votes are closed.