Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago
Edited 4 years ago

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

Log in to vote
2
Answered by
Arkrei 389 Moderation Voter
4 years ago

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)
Ad

Answer this question