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

Why does this touch event disappear whenever another player enters the area?

So, I have a huge invisible brick with CanCollide off around an area, and it's supposed to show the player a gui while they're in that area. However, whenever someone else enters the area, it removes the gui for anyone currently in the area. Any help?

--Hide the indicator
script.Parent.Transparency = 1


--The indicator was touched
script.Parent.Touched:connect(function(touching)
	--Check if the part is part of a player
	local player = game.Players:GetPlayerFromCharacter(touching.Parent)
	
	if player then
		--If the gui doesn't exist, make the gui
		if player.PlayerGui:FindFirstChild("gangTurf") == nil then
			local gui = game.ServerStorage.GuiStore.gangTurf:Clone()
			gui.Parent = player.PlayerGui
			script.Parent.TouchEnded:connect(function(newTouch)
				--If the part that disconnected was from the receiving player, then remove the gui.
				--Prevents weird flashing of the gui.
				local checkPlayer = game.Players:GetPlayerFromCharacter(newTouch.Parent)
				if checkPlayer == player then
					gui:Destroy()	
				end
			end)
		end
	end
end)

3 comments

0

What you could do to prevent the flashing of the gui by using debounce

0

You could save time and use magnitude.

1 answer

while true do
    for i,v in pairs(game.Players:GetChildren()) do
        repeat wait() until v.Character
        if (v.Character.HumanoidRootPart.Position - game.Workspace["PART"].Position).magnitude <= 10 then --Put the distance from which the player should start seeing the GUI
			GUI.Visible = true
        end
    end
wait()
end

Make sure to run through my script for errors, and make sure to locate the GUI and part from where they are located in your editor.

I HIGHLY ADVISE YOU TO ASK ME ANYTHING IF YOU RUN INTO PROBLEMS!!!

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