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

Following NPC and secret message door? [closed]

Asked by 5 years ago
Edited 5 years ago

REWORDED= I guess no one understood what i was getting at.

I am wanting to know how i would script a door that would open if a specific word was said in game chat, any idea on how to do that?

I am also wondering how you would script a npc to follow you when you turned around, like morgennes NPCs. (Check her game out) Im very curious, if you have any info on how i would formulate the script tell me. i am NOT asking for you to MAKE me a script. Obviously. I want to learn to DO IT MYSELF. If i can learn how to do it i wont be here much longer, thank you for your time.

1
Not a request site! User#19524 175 — 5y
0
Not requesting. I have no idea how to script it, so i am asking how i would do it. Yellow9776 0 — 5y
0
You ARE requesting. You’re asking for someone to make the code for you. User#19524 175 — 5y
0
Uhm? no? Im asking if anyone knows how to do it, as in HELP me make it. Yellow9776 0 — 5y
View all comments (4 more)
0
Also whats your issue. is it cause im a noob? I came to this website to help me script what i needed. Not to be annoyed. Yellow9776 0 — 5y
0
Well, help would be you have ALREADY attempted it, but it doesn’t work. User#19524 175 — 5y
0
Ive been trying for a while now. I just can get it right, which is why i have signed up for this sight. I would'nt be here if there was a tutorial. Yellow9776 0 — 5y
0
You need to attempt it on your own then post what script you have tried. Then you can ask for help. Not before. We will not spoon feed you the answer. This is a scripting helpers website. Not a we write the code for you website. We will take what you have tried and help you with it. Please try to post better questions in the future. User#21908 42 — 5y

Closed as Not Constructive by User#19524, User#21908, and LateralLace

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?

1 answer

Log in to vote
-1
Answered by 5 years ago

For the first one you do something as simple as:

--LocalScript

local ply = game.Players.LocalPlayer
local key = ""
local door = game.Workspace.Door

ply.Chatted:connect(function(msg,rcp)   --message, recipient
    if msg == key and door.CanCollide then
        door.CanCollide = false --Not needed if your door relies on a hinge, also make sure the door is anchored if not
    end
end)

Don't know who or what that is so I'm gonna assume from your description that it's a chase on sight npc:

--Localscript again
local ply = game.Players.LocalPlayer
local cam = game.Workspace.CurrentCamera    --Player's current camera
local npc = game.Workspace.Npc
local runService = game:GetService("RunService")    --Better than while loop imo

local function isLooking()
    local val = npc:FindFirstChild("Target").Value
    if not val or val and not val.Parent then
        local pos = cam:WorldToScreenPoint(npc.PrimaryPart.Position)    --Gets a points position on the screen
        local maxDistance = 100 --Change to whatever works for you
        local distance = (npc.PrimaryPart.Position-ply.Character.PrimaryPart.Position).magnitude    --Gets distance between two parts

        if distance <= maxDistance and pos.Z > -1 then  -- -1 means its behind the camera
            npc:FindFirstChild("Target").Value = ply.Character
        end
    end
end
runService:BindToRenderStep("isLooking",0,search())

Put this in a script under the Npc:

local target = script.Parent:FindFirstChild("Target")

target.Changed:connect(function(val)
    --Code to move the character around because I'm too tired to write anymore
end)

No clue how any of this performs on a server or has any errors, but hope it helps.

Ad