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

Touched Event Function not working for GUI?

Hi! So i was trying a simple script for the first time and it had an error, the problem with my script was it didnt pop a GUI according to this script, i am a bit new to the scripting language so dont judge by my level please, thanks.


game.Workspace.F.Touched:Connect(function()
	local GUI = game.StarterGui.F
	if game.Workspace.F.Touched then
	 GUI.Enabled = true
	wait(5)
	GUI.Enabled = false
end)

Dev Console couldnt detect the problem too so idk what was the problem, the GUI (F in StarterGUI) was false on being enabled at default, so what i expected from this script is that touching the part (F in workspace) will pop up the GUI and after waiting 5 secs, it will close... Please let me know how i can fix this, thanks so much!

3 comments

0

You will need to use remote events

0

If this is a server script, then it probably didn't work because server scripts can't access PlayerGUI, and you have to enable the GUI through the PlayerGUI not StarterGUI because all of the players would only see the change after they reset

0

is f a part or a model or something because you can only touch actual physical things you cant touch guis

1 answer

✓ Accepted answer

Here is how you would do it:

game.Workspace.F.Touched:Connect(function(hit)

	if hit.Parent:FindFirstChild("Humanoid") then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		game.Players[player.Name].PlayerGui.F.Enabled = true
		wait(5)
		game.Players[player.Name].PlayerGui.F.Enabled = false
	end

end)

Hope it helps.

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