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

TweenPosition GUI is full of bugs and doesnt work how its intended, how to fix?

Asked by 2 years ago

So i have this Fruit Stall, when ever you walk up to the front part and touch it a GUI will pop up on your screen with a few food items on it and when you click close the GUI will disappear. However, Its not been working the way I've intended it to so, not even touching the part can open the GUI sometimes, the closing animation works about half the time, also I've been finding that when you walk up to the stand and touch the part the closing animation will work and not the opening animation.

Here is my code:

local stall = game.Workspace.FoodStand.FrontPart
local screenUI = script.Parent
local FoodStallGUI = script.Parent.Gradient
local foodItems = script.Parent.Parent
local frame = script.Parent.Frame

screenUI.Enabled = false
foodItems.Enabled = false

stall.Touched:Connect(function()    

    screenUI.Enabled = true
    foodItems.Enabled = true
    frame.Size = UDim2.new(0, 1479,0, 351)
    frame:TweenPosition(
        UDim2.new(0.09, 0,0.366, 0), -- End Position
        "In", -- Easing Direction
        "Linear", -- Easing Style
        1, -- Time in Seconds
        false
    )

    FoodStallGUI:TweenPosition(
        UDim2.new(0.122, 0, 0.139, 0), -- End Position
        "Out", -- Easing Direction
        "Quint", -- Easing Style
        1, -- Time in Seconds
        false
    )


end)

Here is my Button Code:

local button = script.Parent

local frame = game.Players.LocalPlayer.PlayerGui.ScreenGUI.FruitStall.Gradient -- Foods
local FoodStallGUI = game.Players.LocalPlayer.PlayerGui.ScreenGUI.FruitStall.Frame
local t = game.Players.LocalPlayer.PlayerGui.ScreenGUI.FruitStall -- Background



button.MouseButton1Click:Connect(function()
    print("Attempted to close")
    FoodStallGUI:TweenPosition(
        UDim2.new(0.09, 0,0, 0),
        "In", -- Easing Direction
        "Linear", -- Easing Style
        1, -- Time in Seconds
        false
    )
    frame:TweenPosition(
        UDim2.new(0.106, 0,-0.545, 0),
        "In", -- Easing Direction
        "Linear", -- Easing Style
        1, -- Time in Seconds
        false
    )
    t.Enabled = false

    print("closed")
end)

Here is my explorer: Explorer Image

Here is my GUI: GUI Image

My GUI glitching out and opening with closing animation: GUI Glitch

0
ALSO just realised that randomly the GUI just pops up, without even touching it. You could be on the other side of the map and it just pops up lol Sonnymacko 19 — 2y

3 answers

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

Hello Sonnymacko,

My name is The_PumpkinPresident (formerly ZakOMGmcpe564) and I'd be happy to help you with your problem.

You're going to need a RemoteEvent, as the stall in most likely server-sided and the UI is client sided. Insert a RemoteEvent into the ReplicatedStorage and call it whatever. For this sake, I'm going to pretend it's called "OpenGui".

Then do this code once the stall is clicked:

local rs = game.ReplicatedStorage
local event = rs.OpenGui

OpenGui:FireClient(player)

Then, in a localscript inside of the Gui, type this:

local rs = game.ReplicatedStorage
local event = rs.OpenGui

OpenGui:OnClientEvent:Connect(function()
local tweenservice = game:GetService("TweenService")
    local tweenInfo = TweenInfo.new(
        1, -- time
        Enum.EasingStyle.Linear, -- Style
        Enum.EasingDirection.InOut, -- direction
        0, -- when less than zero the tween will loop indefinitely
        false, -- tween will reverse once reaching it's goal
        0 -- DelayTime
    )

    local tween = tweenservice:Create(FloodStallGUI, tweenInfo, {Position = UDim2.new(0.09, 0,0, 0)})
    tween:Play()
end)

If that doesn't work, chances are the position is being altered somehow, for instance, by a UIListLayout.

Please reply to this answer is you're facing any issues.

Hope this helps!

0
Also, alter the position to your liking. ZakOMGmcpe564 52 — 2y
0
What do you mean by, "When the stall is clicked" Are you talking about when the player touches the stall, or when the player clicks "Close" on the stall GUI? Also I'm guessing that is in a script not a local script? Sonnymacko 19 — 2y
0
When the player touches the stall; when it is activated. ZakOMGmcpe564 52 — 2y
0
thanks for ur coments, you are doing something wrong pls send me a pick of your scripts and gui properties sne_123456 439 — 2y
Ad
Log in to vote
0
Answered by 2 years ago

Hello, i might be able to help,

so basically your code tells me you are tweening the food items and the frame separately...

However, tween only work one at a time, so the code starts with tweening the food items but this tween get overridden at times by the code underneath telling it to tween the frame now, this isnt a glitch its just that only your frame will tween....

To solve this, just anchor the food items gui with an offset of 0 and tween the whole frame with the food items at once, and it wont glitch, hope this helps

0
Well It seems to work better, tho I can't know for sure since i need to place my GUI off the screen before the animation starts so it looks better how ever for some reason i can't drag my frame, all this is stopping is the GUI having a better animation. There is something else that keeps happening tho, when I am playing my game, idk if its after a few seconds or if i walk in a certain area but Sonnymacko 19 — 2y
0
The GUI seems to pop up randomly without you having to touch the part, and it doesnt even do the animation Sonnymacko 19 — 2y
Log in to vote
0
Answered by 2 years ago
game.Players.LocalPlayer.PlayerGui.ScreenGui:TweenPosition(Udim2.new(1,1,1), "In", "Linear", 3, true)

Answer this question