Why is this basic Touch Event not working?

So what im wanting is a note to pop up but it won’t and heres the script and output. I feel like the scripts right but maybe it has something to do with a local script? But anyways heres script

local StarterGui = game:GetService("StarterGui")

local DoubleJumpNote = StarterGui.DoubleJumpNote
local part = workspace.DoubleJumpNote

part.Touched:Connect(function()
	if DoubleJumpNote.SeenNote.Value == false then 
		DoubleJumpNote.MainFrame.Visible = true
		print("frame made visible")
		DoubleJumpNote.SeenNote.Value = true
	elseif DoubleJumpNote.SeenNote.Value == true then 
		print("Player has already seen note")
	end
end)

Also when I turn the frame to visible in studio it shows.

Well, this should really be a local script, but the main issue is that you are checking StarterGui and not PlayerGui.
Here’s a local script (in StarterGui)

local plr = game.Players.LocalPlayer
local PlayerGui = plr.PlayerGui
local DoubleJumpNote = PlayerGui:WaitForChild("DoubleJumpNote")

local part = workspace.DoubleJumpNote

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

	if hitplr == plr then
		if DoubleJumpNote.SeenNote.Value == false then 
			DoubleJumpNote.MainFrame.Visible = true
			print("frame made visible")
			DoubleJumpNote.SeenNote.Value = true
		elseif DoubleJumpNote.SeenNote.Value == true then 
			print("Player has already seen note")
		end
	end
end)
1 Like

Adding on to what Kaid3d22 said, the GUI you are changing is the one in StarterGui, while players see the gui in their PlayerGui (a copy of the one in StarterGui, but updates to the one in StarterGui don’t change the one in PlayerGui).

If you want this to be a server script (follow Kaid3n22’s advice if you want it to be a local script), you need to get the character from the hit and use the character to get the player. Once you get the player, you can get the player gui. Here is an example:

local StarterGui = game:GetService("StarterGui")
local Players = game:GetService("Players")

local DoubleJumpNote = StarterGui.DoubleJumpNote
local part = workspace.DoubleJumpNote

part.Touched:Connect(function(hit)
	-- `hit` is the part that hit the "DoubleJumpNote" part
	local character = hit.Parent
	local player = Players:GetPlayerFromCharacter(character)
	if not player then
		-- Ends the function early if the hit wasn't from a character
		return
	end
	-- This next line assumes DoubleJumpNote is in the PlayerGui.
	local DoubleJumpNote = player.PlayerGui.DoubleJumpNote
	if DoubleJumpNote.SeenNote.Value == false then 
		DoubleJumpNote.MainFrame.Visible = true
		print("frame made visible")
		DoubleJumpNote.SeenNote.Value = true
	elseif DoubleJumpNote.SeenNote.Value == true then 
		print("Player has already seen note")
	end
end)

If you want a GUI to be popped-up, be client-sided or maybe do
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
Player:FindFirstChild(“PlayerGui”):WaitForChilld(whatever screen ui is):WaitForChild(whatever UI is)

Now add the code you want to execute.

it is a local script I just got mixed up lol thanks so much!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.