#Beginner Script not working

49 messages · Page 1 of 1 (latest)

scarlet delta
#

im trying to make a gui appear when I walk on/into a part. I thought I had the script finished, but when I tested it, the Frame wouldn't turn visible

#
script.Parent.Touched:Connect(function(Part)
    if Part.Parent:FindFirstChild("Humanoid") then
        game.StarterGui.Shop.Frame.Visible = true
    end
end)
#

script ^^

solid flicker
scarlet delta
#

so switch it from StarterGui to PlayerGui

tepid wagonBOT
#

studio** You are now Level 3! **studio

scarlet delta
#

now it says that PlayerGui is not a member of game

sinful marlin
#

try doing

local Player = game.Players:GetPlayerFromCharacter(Part.Parent)
#

then get the PlayerGui from the Player

scarlet delta
#

ok, ill try that

sinful marlin
#

since its only getting the Gui not the PlayerGui

#

and do a Debouce

#

so its not opening

scarlet delta
#

i was gonna add that after I got it to open

sinful marlin
#

so do if NotOpen then

#

it will close the Frame

#
local Open = false
script.Parent.Touched:Connect(function(Part)
    if Part.Parent:FindFirstChild("Humanoid") then
        local Player = game.Players:GetPlayerFromCharacter(Part.Parent)
        if Open then
            Open = true
            local PlayerGui = Player:FindFirstChild('PlayerGui'):FindFirstChild('ScreenGui')
            local Frame = PlayerGui.Frame
            Frame.Visible = true
            task.wait(2)
            Open = false
            Frame.Visible = false
        end
    end
end)```
scarlet delta
#

did you jsut make the script for me?

sinful marlin
#

ye

scarlet delta
#

should I replace ScreenGui with what I have it named as?

sinful marlin
#

yes

#

if its Named what u have it as

scarlet delta
#

it still isnt working

#

I probably made something wrong

#

nothing is showing up as an error in the output

#

wait, I might have it

#

nope

sinful marlin
#
local Open = false
script.Parent.Touched:Connect(function(Part)
    if Part.Parent:FindFirstChild("Humanoid") then
        local Player = game.Players:GetPlayerFromCharacter(Part.Parent)
        if not Open then
            Open = true
            local PlayerGui = Player:FindFirstChild('PlayerGui')
            local ScreenGui = PlayerGui:FindFirstChild('ScreenGui')
            if ScreenGui then
                local Frame = ScreenGui.Frame
                Frame.Visible = true
            end
        end
    end
end)

script.Parent.TouchEnded:Connect(function(Part)
    if Part.Parent:FindFirstChild("Humanoid") then
        local Player = game.Players:GetPlayerFromCharacter(Part.Parent)
        if Open then
            Open = false
            local PlayerGui = Player:FindFirstChild('PlayerGui')
            local ScreenGui = PlayerGui:FindFirstChild('ScreenGui')
            if ScreenGui then
                local Frame = ScreenGui.Frame
                Frame.Visible = false
            end
        end
    end
end)```
#

now retry then edit it so its going to set

#

and u can change this linelua if ScreenGui then

#

to lua if PlayerGui and ScreenGui then

#

on both

scarlet delta
#

its working now

#

but

#

when im walking on the part, the gui is flashing, but if I stand still it works

#

so its working but not visually apealing

#

you dont have to help me anymore if you dont want to

sinful marlin
#

I’m going to fix it for u to make it not flash for each step on part

scarlet delta
#

ty ty

#

I might as well just do team create with you XDD

sinful marlin
#
local Open = false

script.Parent.Touched:Connect(function(Part)
    if Part.Parent:FindFirstChild("Humanoid") then
        local Player = game.Players:GetPlayerFromCharacter(Part.Parent)
        if not Open then
            Open = true
            local PlayerGui = Player:FindFirstChild('PlayerGui')
            local ScreenGui = PlayerGui:FindFirstChild('ScreenGui')
            if ScreenGui then
                local Frame = ScreenGui.Frame
                Frame.Visible = true
            end
        end
    end
end)

script.Parent.TouchEnded:Connect(function(Part)
    if Part.Parent:FindFirstChild("Humanoid") then
        local Player = game.Players:GetPlayerFromCharacter(Part.Parent)
        if Open then
            Open = false
            local PlayerGui = Player:FindFirstChild('PlayerGui')
            local ScreenGui = PlayerGui:FindFirstChild('ScreenGui')
            if ScreenGui then
                local Frame = ScreenGui.Frame
                Frame.Visible = false
            end
        end
    end
end)```
scarlet delta
#

should I change if Screen Gui to if Screen Gui and PlayerGui??

sinful marlin
#

just change it to the Name that u have for the ScreenGui

#

which is here

scarlet delta
#

yeah

#

but for if Screen Gui then

#

like on line 10

#

also now it closes after like 3 sec

sinful marlin
#

Just add a else