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

screengui won't show with a touched event?

I still can't get this to work, so I decided to simplify my question. I want to make the gui show when the block is touched (for the person who touched it.) I then want the gui's text to change, in this case, "Hello!" Here is one of the scripts I tried. I want to text to NOT change until the block is touched.

local function onTouch(hit)
	if (hit.Parent:FindFirstChild("Humanoid") == nil) then
		game.Players.LocalPlayer.PlayerGui.ScreenGui.Enabled = true
		setText = "Hello!"
	end
end

workspace.indicator1.Touched:Connect(onTouch)

This code is a bit wonky but this is the closest thing that made sense on what I was attempting. I apologize if this is a dumb question (I am new to coding,) but I can't find this anywhere, and everything I do find doesn't work with what I am trying to do. Thank you so much.

3 comments

0

This is in a local script, which is inside StarterGui > ScreenGui > Frame > TextLabel.

0

Edited my cide.

0

Edited again, apologies.

2 answers

I believe you meant if it's not a nil, then make it enabled.


local function onTouch(hit)
    if game.Players.LocalPlayer.PlayerGui.ScreenGui.Enabled ~= true then
        if (hit.Parent:FindFirstChild("Humanoid") ~= nil) then
            game.Players.LocalPlayer.PlayerGui.ScreenGui.Enabled = true
            setText = "Hello!"
        end
    end
end

workspace.indicator1.Touched:Connect(onTouch)

btw, make sure settext is a variable

6 comments

0

thank you! the script works, but the only problem is as long as I am standing on the block, "Hello!" is spammed over and over again, is there anyway I can fix this? thank you!!

0

Yes, add debounce.

0

nvm

0

I'm so sorry for bothering you again but this time the new code now doesn't work at all, when I touch the block nothing happens. Should I try using debounce?

0

edited again srry

0

thank you so much that seemed to work! ill accept your answer but I was wondering if there was a way for the event to only occur once. could i do that with the code or would I have to make a new one? thank you!

I'll continue for @raidn6.

Step one:

Make a remote function in ReplicatedStorage, call it "ShowGUI".

Step two:

Make a local script inside of your gui and make a normal script inside of the part that will trigger it.

Step three:

Add this inside of the local script:

local uiToShow = yourObject

local showGUI = game.ReplicatedStorage.ShowGUI

local hasShown = false

showGUI.OnClientInvoke = function()
	if hasShown = false then
		hasShown = true
		uiToShow.Visible = true
		wait(5)
		uiToShow.Visible = false
		return true
	else
		return false
	end
end

Step four:

Add this inside of the script inside of the part that will trigger it:

local part = script.Parent

local showGUI = game.ReplicatedStorage.ShowGUI

part.Touched:Connect(function(hit)
	local plr = game.Players:GetPlayerFromCharacter(hit.Parent)

	if plr then
		local result = showGUI:InvokeClient(plr)

		if result = true then
			print("Showed GUI for: "..plr.Name)
		end
	end
end)

Hope this helps,

Dexiber.

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