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

Why is my textlabel going up but not down i don't get it?? (Ansvered)

When I touch a part it should bring up and down a text label but it doesn't go down why is that?

local hitbox = workspace.Shop.HitBox_Tool_Shop
local player = game.Players.LocalPlayer
local ui = player.PlayerGui:WaitForChild("E").TextLabel
-------------------------------------------------

hitbox.Touched:Connect(function()
			ui:TweenPosition(UDim2.new(0.446, 0,0.772, 0),"Out","Quad",1)
			wait(0.1)
	end)

----------------------------------------------------

local hitbox = workspace.Shop.HitBox_Tool_Shop
local userinput = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local ui = player.PlayerGui:WaitForChild("E").TextLabel

---------------------------------------------------------
hitbox.TouchEnded:Connect(function()
		ui:TweenPosition(UDim2.new(0.442, 0,1.999, 1),"Out","Quad",1)
	end)

1 answer

✓ Accepted answer

TouchedEnded is incredibly unreliable and inconsistent. I'd recommend using region3 or if this is in a localscript you can have the gui show up when the localplayers character is within a certain distance to the hitbox like so:

local player = game.Players.LocalPlayer
local char = player.Character
local replicatedStorage = game:GetService("ReplicatedStorage")
local trigger = workspace.HitBox

local open = false

game:GetService("RunService").RenderStepped:Connect(function()
local distance = (char:WaitForChild("HumanoidRootPart").Position - trigger.Position).Magnitude
if distance <= 7 then
    if not open then
		open = true
    	-- in range
    end
else
    if open then
        open = false
        -- out of range
    end
end
end)

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