I am trying to make it so that a Gui pops up when a player goes inside a certain region.

In order to do this I am using a function that fires for each player that was found within the function.

The toggle for the Gui works once, but after that it will not toggle again (though the final print statement runs). At first I made the function set a player on fire if they're in the region and this fired again if the fire was put out of the player.

How would I resolve this please?

-- effect of being in region
	for plrName, char in pairs (playersFound) do
		spawn(function()
			print("FUNCTION")
			local player = game.Players:GetPlayerFromCharacter(game.Workspace:FindFirstChild(char))
			local playerGui = player.PlayerGui.ScreenGui.Frame
			print(playerGui)
			playerGui.Visible = true
			print("Testing")
		end)
	end

EDIT I have currently managed to get a toggle working using the "Touch" and ":Clone()" event - these likely aren't the most efficient methods and following the same lines I could probably get Region3 and :Clone() to work together (if you know a more efficient method of this please let me know!)

local gui = game.Workspace.ScreenGui
--local debounce = false

function showGui(player)
	if player.PlayerGui:FindFirstChild("ScreenGui") == nil then
		--debounce = true
		gui:Clone().Parent = player.PlayerGui
		player.PlayerGui.ScreenGui.Frame.Toggle.MouseButton1Click:Connect(function()
			player.PlayerGui.ScreenGui:Destroy()
			--debounce = false
		end)
	end
end

script.Parent.Touched:Connect(function(part)
	if part.Parent:FindFirstChild("Humanoid", 60) ~= nil then
		local player = game.Players:GetPlayerFromCharacter(part.Parent)
		showGui(player)
	end
end)

2 comments

0

Maybe try using "TouchEnded" events with some debounce variables?

0

Thank you for suggesting using "TouchEnded" (is where I worked out how to use "Touch").