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

Why is this gui occasionally sticking after the player has stopped touching the brick?

This is supposed to trigger a screen gui for the player when they touch a brick, keep the gui up while they remain touching that brick, and then remove the gui once the touch ends. For the most part, it works. However, occassionally, the gui will flicker while they run into the brick, and even more rarely sometimes the gui gets stuck on the screen, even though the player has long since walked away from the brick.

Does anyone have any advice on how I can solve this? I feel like I must not be using debounces properly, but I'm having a very hard time figuring out what exactly I'm doing wrong.

script.Parent.Transparency = 1 
local inRange = false
local isTouched = false
local store = script.StoreScript
local debounce = false
local eDebounce = false
local range = false

--Remote Events
local storeGuiEvent = Instance.new("RemoteEvent")
storeGuiEvent.Parent = game.ReplicatedStorage
storeGuiEvent.Name = "storeGuiEvent"

local storeGuiEventEnd = Instance.new("RemoteEvent")
storeGuiEventEnd.Parent = game.ReplicatedStorage
storeGuiEventEnd.Name = "storeGuiEventEnd"

local createStoreRequest = Instance.new("RemoteEvent")
createStoreRequest.Parent = game.ReplicatedStorage
createStoreRequest.Name = "CreateStoreRequest"



function onTouch(HIT)
		if inRange == false then
			local H = HIT.Parent:FindFirstChild("Humanoid")
			if range == false then
				range = true
				if H and not debounce and range == true then
					debounce = true
					character = HIT.Parent
					Player = game.Players:GetPlayerFromCharacter(HIT.Parent)
					print("Fire")
					storeGuiEvent:FireClient(Player)
					debounce = false
					inRange = true
				end

			end
		end

end


function endTouch(END)
	local E = END.Parent:FindFirstChild("Humanoid")
	if E and not eDebounce then
		eDebounce = true
		if Player == nil then
			return
		else 
			storeGuiEventEnd:FireClient(Player)
		inRange = false
		end
		eDebounce = false
		range = false
	end
end


function onCreateStoreRequested(player)
	store:Clone().Parent = character
end





script.Parent.Touched:connect(onTouch)
script.Parent.TouchEnded:connect(endTouch)
createStoreRequest.OnServerEvent:Connect(onCreateStoreRequested)

1 answer

After a few seconds, whenever you want it to dissapear do this

wait( fill your number in here)

script.parent.destroy()

check it it will maybe work

1 comment

0

Sorry it's taken me so long to respond! This doesn't quite explain why the issue occasionally happens... but it does give me a viable solution to deal with it when it does happen. Instead of destroying the script, I just call the Gui End event that I made after the wait. Works really well, thanks!

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