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

How To Make A Clickable GUI When Looking At Part?

Asked by 10 years ago

Hi I'm trying to create a script for doors in my game so that when the player looks at them a text button will appear saying "Open". When said Gui is clicked the door will open. Just as well, when the door is open the Gui will say "Close". Here's the code I currently have:

1mouse.Button1Down:connect(function()
2    if mouse.Target == workspace.TestDoor
3    and player:DistanceFromCharacter(mouse.Target.Position)<15 then
4        if mouse.Target.Clicked.Value == true then
5            mouse.Target.Clicked.Value = false
6        else mouse.Target.Clicked.Value = true
7        end
8    end
9end)

So what's happening here is that I have a test door named "TestDoor". When the mouse clicks the script checks if that target is specifically TestDoor and that the player is at least 15 units away from it. If all this is true then there is a value within TestDoor called Clicked which is changed. I have a script within TestDoor that does this to make sure the previous script is working:

1while true do
2    wait(2)
3    print(script.Parent.Clicked.Value)
4end

Also, the first script is placed in the players backpack which I'm not sure is the proper area. I've done a lot of programming in the past but am new with scripting for Roblox.

As for the gui part I've tried things like this but to no avail:

1if mouse.Target   == workspace.TestDoor and
2player:DistanceFromCharacter(mouse.Target.Position)<15 then
3    local screen  =  Instance.new("ScreenGui")
4    screen.Parent =  player.PlayerGui
5    local button  =  Instance.new("TextButton")
6    button.Parent =  screen
7end

So I'm at a bit of a loss when it comes to detecting when the player is looking at the door from a specific distance away. Just a side note: ClickDetectors are out of the question since they don't have the functionality I require. More specifically you cannot tell whether someone right or left clicked with a click detector.

Anyway, if someone could point me in the right direction on how I should go about doing this it would be greatly appreciated. Thanks!

Answer this question