How can I TweenSize the GUI when the a player comes in contact with a certain brick and it comes down but when they leave if the magnitude is less than 5, it goes away by going up. My GUI is called "Shop" and it's inside of the script.
function touch(hit) if game.Players:findFirstChild(hit.Parent.Name) ~= nil then local player = game.Players[hit.Parent.Name] if player.PlayerGui:findFirstChild("Shop") == nil then local gui = script.Shop:clone() gui.Parent = player.PlayerGui repeat wait() until (player.Character.HumanoidRootPart.Position - script.Parent.Position).magnitude > 5 gui:remove() end end end script.Parent.Touched:connect(touch)
A simple fix to this would be to TweenPosition it or TweenSizeAndPosition if you want it to grow and move onto your screen.
In this example I use TweenPosition for simplicity and efficiency however you may edit it to your liking.
Script Inside Part
local Delay = 3 -- Time it takes to scroll down / up function onTouch(hit) if game.Players:FindFirstChild(hit.Parent.Name) then local player = game.Players:GetPlayerFromCharacter(hit.Parent) if not player.PlayerGui:FindFirstChild("Shop") then local gui = script.Shop:Clone() gui.Parent = player.PlayerGui gui.Frame:TweenPosition(UDim2.new(.5,0,.5,0),"Out","Quad",Delay,true) repeat wait() until (player.Character.HumanoidRootPart.Position - script.Parent.Position).magnitude > 5 gui.Frame:TweenPosition(UDim2.new(.5,0,-.5,0),"Out","Quad",Delay,true) wait(Delay) gui:Remove() end end end script.Parent.Touched:Connect(onTouch)