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

How can we actually create interactive doors, things in general?

Asked by 8 years ago
Edited 8 years ago

This is a simple question.

I'm actually trying to figure out how can anyone make some interactive doors, things or anything.

Some Examples: - When close to a door, it shows: Press E to Open. - When close to a game item, it shows: Press T to Obtain.

Thanks for answering! :D

Nice day or night!

1 answer

Log in to vote
1
Answered by 8 years ago
Edited 8 years ago

Use magnitude

Example:

local player = game.Players.LocalPlayer
local char = player.Character

if (char.Torso.Position - workspace.Door.Position).magnitude >=5 then
    player.PlayerGui.ScreenGui.Frame.Visible = true
end

To make the door open after this GUI is shown, simply use UserInputService

And whenever the key to open the door (let's say E), then check if the Frame is visible, and if it is, you can then create your own things.

I'll teach you how this service works, so you know next time, it helps a lot.

We'll start by obtaining this service.

local UIS = game:GetService("UserInputService")

function onKeyPress(key)
    if key.KeyCode == Enum.KeyCode.E and player.PlayerGui.ScreenGui.Frame.Visible == true then
        OpenDoor() -- Link to the open door function, which has your own code to open the door.
    end
end

UIS.InputBegan:connect(onKeyPress)

Create your own OpenDoor function like this:

function OpenDoor()
    -- code to open door here
end

-- or

local OpenDoor = function()
    -- code to open door here
end

Hope I helped! If you are confused about ANYTHING regarding GUI's, UserInputService, I will be more than happy to provide links or information.

Also PLEASE accept my answer, if it helped you, or if it was right.

0
But, the GUI doens't show up, it is in starterGui TheCoolRobloxian4 20 — 8y
1
No, this isn't how GUI's work. All content in StarterGUI, are copied into the PlayerGUI. Using StarterGUI, would make every player see it. DaCrazyDev 444 — 8y
0
Oh thanks! TheCoolRobloxian4 20 — 8y
1
Np. Remember, feel free to ask me more questions, I'm very open, and happy to help =) DaCrazyDev 444 — 8y
Ad

Answer this question