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

How do I make a gui appear when the player is touching a part by a script?

Asked by 5 years ago
Edited 5 years ago

I wanted to make a script where when a player touches a part a gui appears for the player who touched it but I can't I tried the script.

`script.Parent.Touched:Connect(function(hit)
if hit.parent:FindFirstChild("Humanoid") then
local blue = hit.Parent
game.StarterGui.Nice.Frame.Visible = true
end
end)

Sadly, it wont work, I searched it on the internet but none of them explained properly or I couldn't find it. Please help me make it work. Thank you if you do.

0
rip u TheluaBanana 946 — 5y
0
and i am not grammar nazi TheluaBanana 946 — 5y
0
also ull have to list all the other things one is capable of ripping if u really hardcore person TheluaBanana 946 — 5y
0
Are you wanting to make it go away after the user stops touching the brick? BashGuy10 384 — 5y
View all comments (11 more)
0
maybe TheluaBanana 946 — 5y
0
also if this really is not ur style u can always just change the GUI to a part or meshPart and make that transparent / not transparent when the player touches it. dont face ur problems, go around them TheluaBanana 946 — 5y
0
if you are going to do that, use the TouchEnded event BashGuy10 384 — 5y
0
I was also trying to do that but I was focusing on making it appear on the brick first. turquoise_monkeyman 32 — 5y
0
could be a problem with the how the roblox touch event works in the situation that its not a problem with ur script. If so make ur own touch event before continuing. TheluaBanana 946 — 5y
0
also there is typo on line 2; parent is uppercase "P" TheluaBanana 946 — 5y
0
alright just saying; says the grammar nazi TheluaBanana 946 — 5y
0
can somone please help me   turquoise_monkeyman 32 — 5y
0
Why does it say that you want to touch a script? No such thing is possible. DeceptiveCaster 3761 — 5y
0
o yeah! TheluaBanana 946 — 5y
0
actually check the name turquoise_monkeyman 32 — 5y

2 answers

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

You requested the script for situation to show the GUI only when the player is touching the part. This is still a Local Script so put it inside your GUI.

  • I had some time so I created even more advanced script with more options just for you.

Updated Code:

local Workspace = game.Workspace

local Tpart = Workspace:WaitForChild("Part") -- Defines a way to a part.

local Players = game:GetService("Players")

-- Code starts here

local deb = 0

-- Makes the frame visible

Tpart.Touched:Connect(function(hit)

if deb == 0 then

deb = 1

local char = hit.Parent

if char then

local hum = char:WaitForChild("Humanoid")

if hum ~= nil then

print("Opening the Gui")

local Player = Players:GetPlayerFromCharacter(char)

local PlayerGui = Player.PlayerGui

local GuiToBeOpened = PlayerGui:WaitForChild("Nice")

GuiToBeOpened.Frame.Visible = true

end

end

end

end)

-- ?? Disappears the frame

Tpart.TouchEnded:Connect(function(hit)

if deb == 1 then

deb = 0

local char = hit.Parent

if char then

local hum = char:WaitForChild("Humanoid")

if hum ~= nil then

print("Opening the Gui")

local Player = Players:GetPlayerFromCharacter(char)

local PlayerGui = Player.PlayerGui

local GuiToBeOpened = PlayerGui:WaitForChild("Nice")

GuiToBeOpened.Frame.Visible = false

end

end

end

end)
0
Thank you so so so so so so so so so so so so so so so so so so so so so so so so so so so so so so so so so so so so so so so so much turquoise_monkeyman 32 — 5y
0
how do I make it invisible when the person isn't on the part you dont need to answer it but thank you if you do turquoise_monkeyman 32 — 5y
0
Alright AswormeDorijan111 531 — 5y
0
Do you wanna create a GUI visible only when the person is touching the part? AswormeDorijan111 531 — 5y
View all comments (4 more)
0
yes turquoise_monkeyman 32 — 5y
0
Alright, I'll edit the script and notify you when I'm done. AswormeDorijan111 531 — 5y
0
THANK YOU SO SO SO MUCH turquoise_monkeyman 32 — 5y
0
Your welcome AswormeDorijan111 531 — 5y
Ad
Log in to vote
0
Answered by
Norbunny 555 Moderation Voter
5 years ago
Edited 5 years ago

The StarterGui is the placeholder for the GUIs to be loaded later on for the different players.

Assuming by this "oopsie", I suppose that you are not very experienced into programming, so I'll keep the answer simple for you:

script.Parent.Touched:Connect(function(hit)
    -- Checking if it's a character(by having a humanoid)
    local hum = hit.Parent:FindFirstChild("Humanoid")
    if(hum) then
        -- method used to find the player
        local player = players:GetPlayerFromCharacter(Hum.Parent)
        if(player) then
            local gui = player.PlayerGui("Nice") -- your GUI's name
            gui.Frame.Visible = true
        end
    end
end)

When the player loads, the GUI is no longer inside of "StarterGui", but in "PlayerGui", found as a child of the player.

0
It isn't showing me the frame and keeps on showing me an error which says attempt to index global 'Players' (a nil value) on line 6 thank you anyway the problem is easily fixed if you add game in front of it I wolud also like to say that on line 6 you put hum with the capital H when you put hum as a variable with a lowercase h and even after that nice isn't appart of the playergui eventough it is  turquoise_monkeyman 32 — 5y
0
heh the "thank you anyway" TheluaBanana 946 — 5y
0
As I see in your code, you haven't defined a variable players you used to get the player. You could've used local Player = game.Players to get the Players service. AswormeDorijan111 531 — 5y

Answer this question