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

GUI is supposed to slide from the side on touch?

Asked by
Rynappel 212 Moderation Voter
4 years ago

I have a script, where you touch a block and a GUI is supposed to slide from the side, but It doesnt. Whats wrong with my script?

local debounce = 0
local menu = script.Parent.Parent.ShopFRAME

script.Parent.Touched:connect(function()

if debounce == 0 then
 debounce = 1

   for i = 1,10 do 
 wait(0.02)
 menu.Position = menu.Position + UDim2.new(0.1125,0, 0,0)
   end
   debounce = 2

elseif debounce == 2 then
 debounce = 1

 for i = 1,10 do
  wait(0.02)
 menu.Position = menu.Position - UDim2.new(0.1125,0, 0,0)
    end
    debounce = 0

 end
end)
0
You should use TweenPosition instead lolzmac 207 — 4y
0
Wdym? can you show me an example? Rynappel 212 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago

Improvements

You can get smooth motion with the TweenService (GuiObjects have their own special function for this). In addition, TweenPosition has a parameter to prevent being overriden

Issues

Assuming this is a Server Script, make sure the Gui is parented to the player's PlayerGui or otherwise use a LocalScript and place the Gui into the StarterGui (in which case you'd have to reference the "part" directly, since otherwise, the Gui would not be visible to the player who touched the part.

Revised Local Script

local part = script.Parent
local menu = part.Parent:WaitForChild("ShopFRAME")
local debounce = false

part.Touched:Connect(function(hit)
    if hit and hit.Parent then
        local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
        if player then
            local pgui = player:WaitForChild("PlayerGui")
            local clone = nil
            if not pgui:FindFirstChild("ShopFrame") then
                clone = menu:Clone()
                clone.Parent = pgui
            else
                clone = pgui:WaitForChild("ShopFrame")
            end

            if debounce == false then
                debounce = true
                clone:TweenPosition(menu.Position + UDim2.new(1.125, 0, 0, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 0.2, false, nil)
            elseif debounce == true then
                debounce = false
                clone:TweenPosition(menu.Position + UDim2.new(-1.125, 0, 0, 0), Enum.EasingDirection.In, Enum.EasingStyle.Linear, 0.2, false, nil)
            end
        end
    end
end)
0
Just did some research on tween position and stuff. I’m an idiot lol Rynappel 212 — 4y
Ad

Answer this question