Frame visibility script not working

Not sure what I am doing wrong, the code simply does nothing. I am trying to make it so when you step on the part called “questmesh” the Frame inside of questgui goes invisible (or its visibility is set to false). What is wrong with my script?

local part = game.Workspace.questmesh
local customframe = game.Players.LocalPlayer.Player.questgui.Frame

local function onPartTouched(otherPart)
	-- Get the other part's parent
	local partParent = otherPart.Parent
	-- Look for a humanoid in the parent
	local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
	if humanoid then
		-- Do something to the humanoid, like set its health to 0
		customframe.Visible = false
	end
end

part.Touched:Connect(onPartTouched)

You can’t get local player from script (only from local script).


local part = game.Workspace.questmesh

local function onPartTouched(otherPart)
	-- Get the other part's parent
	local partParent = otherPart.Parent
	local player = game.Players:GetPlayerFromCharacter(partParent)
	-- Look for a humanoid in the parent
	local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
	if humanoid and player then
		local customframe = player:WaitForChild("PlayerGui"):WaitForChild("questgui").Frame
		-- Do something to the humanoid, like set its health to 0
		customframe.Visible = false
	end
end

part.Touched:Connect(onPartTouched)
2 Likes

it works! Thank u for the help!!

1 Like