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

Tween Position Sliding GUI Not Working? Help Me Please!

Asked by
Rynappel 212 Moderation Voter
4 years ago

I have this script and when you touch a block its supposed to bring up a GUI it doesnt though,

local part = script.Parent
local menu = script.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)

This is what the Hierarchy looks like: https://prnt.sc/px7m24

1 answer

Log in to vote
0
Answered by
ryan32t 306 Moderation Voter
4 years ago

Three Problems (1) Your script only works in a Script not Local Script (2) Instead of only a Frame, you need a Frame inside of a ScreenGui (3) You have to change some parts of your script

Script:

local part = script.Parent
-- Instead of waiting for frame. It looks for gui and frame
local menu = script.Parent:WaitForChild("ShopGui"):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
            -- instead of finding for frame, it finds for gui and frame
            if not pgui:FindFirstChild("ShopGui"):FindFirstChild("ShopFRAME") then
                clone = menu:Clone()
                clone.Parent = pgui
            else
                -- instead of setting clone as only frame, it set clone for gui and frame
                -- this was the last thing that i changed
                clone = pgui:WaitForChild("ShopGui"):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
Doesnt work, it says. Line 13 attempt to index a nil value Rynappel 212 — 4y
0
well hopefully you named the ScreenGui as ShopGui because if you copy and pasted the code then yeah ryan32t 306 — 4y
Ad

Answer this question