#BillboardGUI script

1 messages · Page 1 of 1 (latest)

winter brook
#

Im trying to make it so that when a player enters a part, that is inside an NPC a button will appear.

#
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local Workspace = game:GetService("Workspace")

local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local hrp = character:WaitForChild("HumanoidRootPart")
local button = player:WaitForChild("PlayerGui"):WaitForChild("AskUI"):WaitForChild("Open")
local part = Workspace:WaitForChild("Rig"):WaitForChild("AskSystem"):WaitForChild("Part")

local touching = false

part.Touched:Connect(function(hit)
    if hit:IsDescendantOf(character) then
        touching = true
    end
end)

RunService.RenderStepped:Connect(function()
    if touching and not part:IsTouching(hrp) then
        touching = false
    end

    button.Visible = touching
end)

prisma fiber
#

sooo what's the problem

winter brook
#

it doesnt appear

torpid craneBOT
#

studio** You are now Level 6! **studio

winter brook
#

I heard a ping someone typing to put a code inside, i dont see it tho

shy condor
#

wait

#

here you are @winter brook :

local Players = game:GetService("Players")
local Workspace = game:GetService("Workspace")

local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local hrp = character:WaitForChild("HumanoidRootPart")
local button = player:WaitForChild("PlayerGui"):WaitForChild("AskUI"):WaitForChild("Open")
local part = Workspace:WaitForChild("Rig"):WaitForChild("AskSystem"):WaitForChild("Part")

-- Hide button by default
button.Visible = false

part.Touched:Connect(function(hit)
    if hit:IsDescendantOf(character) then
        button.Visible = true
    end
end)

part.TouchEnded:Connect(function(hit)
    if hit:IsDescendantOf(character) then
        button.Visible = false
    end
end)
#

also show us some directories about the ui, the model, the script etc.

winter brook
#

alr

#

ill try the script

#

the button still doesnt appear

shy condor
#

hm

#

the script you are writting is the ButtonShower as localscript?

#

@winter brook

winter brook
#

yes

shy condor
#

do you have anu print in the console of errors or wanrings?

winter brook
#

nothing

shy condor
#

ok I have a recommendation change this line:
local button = player:WaitForChild("PlayerGui"):WaitForChild("AskUI"):WaitForChild("Open")

to this:
local button = script.Parent.Parent

winter brook
#

okay I did that

shy condor
#

still ?

#

the same problem?

winter brook
#

Visible is not a valid member of BillboardGui "Players.MonkeyTheBestYT.PlayerGui.AskUI"

shy condor
#

ok wait

winter brook
#

just 1 parent

#

not 2

shy condor
#

how?

#

wait

#

you want to show the AskUI right?

winter brook
#

nope, the button called Open

shy condor
#

ok wait

#

to show this you want to enable firstly the ui which means that i found the problem

torpid craneBOT
#

studio** You are now Level 1! **studio

shy condor
#

give me a minute

coral jewel
#
-- Hide button by default
button.Visible = false

part.Touched:Connect(function(hit)
    if hit:IsDescendantOf(character) and not button.Visible then
        button.Visible = true
    end
end)

part.TouchEnded:Connect(function(hit)
    if hit:IsDescendantOf(character) and button.Visible then
        button.Visible = false
    end
end)```
#

Try this

#

or probably add a debounce

shy condor
#
local Players = game:GetService("Players")
local Workspace = game:GetService("Workspace")

local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local hrp = character:WaitForChild("HumanoidRootPart")
local button = scipt.Parent
local ui = script.Parent.Parent
local part = Workspace:WaitForChild("Rig"):WaitForChild("AskSystem"):WaitForChild("Part")

-- Hide button by default
button.Visible = false
ui.Enabled = false

part.Touched:Connect(function(hit)
    if hit:IsDescendantOf(character) then
        ui.Enabled = true
        button.Visible = true
    end
end)

part.TouchEnded:Connect(function(hit)
    if hit:IsDescendantOf(character) then
        ui.Enabled = false
        button.Visible = false
    end
end)
#

try one of those we sent and say if it is working

#

@winter brook

winter brook
#

I also corrected that typo

winter brook
#

Both didnt work

coral jewel
#

Remove the touch ended connection

#

or like comment it out

#

and test the Touched connection

#
-- Hide button by default
button.Visible = false

part.Touched:Connect(function(hit)
    if hit:IsDescendantOf(character) then
        button.Visible = true
    end
end)
--part.TouchEnded:Connect(function(hit)
    --if hit:IsDescendantOf(character) then
        --button.Visible = false
    --end
--end)

winter brook
#

It still doesnt work, maybe its because the part is invisible?

coral jewel
#

see if it return anything when touched

winter brook
#

nothing

coral jewel
#

ok so the part is never being touched

civic cargo
#

.Touched and .TouchEnded is unreliable asf

winter brook
#

Okay so I realised when I play the game, the position of the part changes

coral jewel
winter brook
#

and now it just gets deleted when I play

civic cargo
#

is this a serverscript

coral jewel
#

check if its anchored 🤦‍♂️

coral jewel
winter brook
#

its is acnhored

civic cargo
#

is this a server script.

winter brook
#

nvm fixed it

coral jewel
#

what was the problem?

winter brook
#

I just changed a property in the part called Locked. Idk why was it on true and why was it making the script not work

#

I dont know what it does aswell

coral jewel
#

that don't make no sense

#

Locked just makes it so you can't click on the part through studio

winter brook