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

How do you make a gui show up when you touch (Not Click) a brick?

Asked by
Timei 6
6 years ago
Edited 6 years ago

I've been trying several methods to for a pop up gui but for some reason I cant seem to get anything to work. I would be really thankful if anyone can tell me how to do this properly. Thanks! (Btw I do have a text button that currently opens the gui idk if that would make a difference or not and the brick is in workspace)

http://imgur.com/a/A1kOew3 This is what the Gui looks like. The "TextButton" is the button that currently opens MainFrame

What I've tried doing


game.Players.PlayerAdded:Connect(function(plr) script.Parent.Touched:connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then plr.PlayerGui.GunShop.MainFrame.Visible = true end end) end)

..

local Part = script.Parent

Part.Touched:connect(function(HIT)
    local H = HIT.Parent:FindFirstChild("Humanoid")
    if H then
            local Player = game.Players:GetPlayerFromCharacter(HIT.Parent)
            Player.PlayerGui.GunShop.MainFrame.Visible = true
    end
end) 


I tried some variants of these two and also some random guesses that I didn't really expect to work :/

0
if you tried 'several methods' you should post them. We aren't mind readers you know User#19524 175 — 6y
0
I'm not completely sure what you're asking, but there is an object called billboard GUI which floats above a brick in a certain position. Pumpk1n52 22 — 6y
0
Through clicking it or touching it? Darkcraft10 20 — 6y
0
Are you thinking like, keybind affects or something? iWagen 5 — 6y
0
Sorry for the confusion I updated it now hopefully it makes more sense Timei 6 — 6y

2 answers

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

So you can achieve this with the Instance.Touched event, however, the server cannot access individual player's guis from a server script, so that must be done locally. Luckily local scripts can detect Touched events of items in workspace, so that helps you do this without the use of a remote event/ remote function.

The goals of the local script should be to : 1) have a touched event 2) check if a body part of the player is touching the part 3) if so, make a GUI pop up

so, here it is

--it should be a LOCAL SCRIPT (putting this here to avoid confusion)
local player = game.Players.LocalPlayer
workspace.Part.Touched:Connect(function(hit)
    if hit and hit.Parent then
        local plr = game.Player:GetPlayerFromCharacter(hit.Parent) 
        if plr and plr == player then
            --player.PlayerGui.ScreenGui.Frame.Visible = true
            player.PlayerGui.ScreenGui.Frame.Visible = not player.PlayerGui.ScreenGui.Frame.Visible
        end
    end
end)

Now what this script does is checks if the thing that touched the part exists and has a parent. If it does exist and has a parent, the script then checks if that part is the player character and if it is, then it checks if it is the local player, which is definable from local script, then if all of that checks out, it turns the visible property of the frame to true or false

rubenkan version

--it should be a LOCAL SCRIPT (putting this here to avoid confusion)
local player = game.Players.LocalPlayer
workspace.Part.Touched:Connect(function(hit)
    if hit:IsDescendantOf(player.Character)
        --player.PlayerGui.ScreenGui.Frame.Visible = true   
    end
end)
0
Might suggest to switch both if statements into one with hit:IsDescendantOf(Player.Character) RubenKan 3615 — 6y
Ad
Log in to vote
-4
Answered by 6 years ago

I have some code for you: (hopefully it works in a real server)

https://imgur.com/a/EY8VYfJ

0
Although this helped me with something its not specifically what Im looking for right now. Basically I want My Gui to pop up when a certain brick located in workspace is touched. Timei 6 — 6y

Answer this question