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

Output is fine.. it does not seem like there are any errors but in game, the script does not work?

Asked by
JMC0077 -4
4 years ago

hi, i'm following a tutorial on how to make a custom NPC chat system and the script does not work and I do not know why

local RunService = game:GetService("RunService")
local UIS = game:GetService("UserInputService")
local Players = game:GetService("Players")








local DetectedNPC = nil
local Detected = false
local Chatting = false
local Skip = false
local Exit = false








local Player = Players.LocalPlayer
local Camera = game.Workspace.CurrentCamera

local Gui = script.Parent
local Sounds = Gui.Sounds
local PromptLabel = Gui.PromptLabel
local LineLabel = Gui.LineLabel








local Character = Player.Character or Player.CharacterAdded:Wait()
local CharHMR = Character:WaitForChild("HumanoidRootPart")








local NPCS = game.Workspace:WaitForChild("NPCS")








UIS.InputBegan:Connect(function(Input)
    if Input.KeyCode == Enum.KeyCode.X then
        if Chatting == true then
            Skip = true
            Sounds.Click:Play()
        end
    end
end)

UIS.InputBegan:Connect(function(Input)
    if Input.KeyCode == Enum.KeyCode.Z then
        if Chatting == true then
            Exit = true
            Sounds.Click:Play()
        end
    end
end)

UIS.InputBegan:Connect(function(Input)
    if Input.KeyCode == Enum.KeyCode.E then


        if Detected == true then
            local Lines = DetectedNPC:FindFirstChild("Lines")

            if Lines then
                Sounds.Click:Play()

                Chatting = true
                Detected = false

                LineLabel.Text = " "

                PromptLabel:TweenSize(UDim2.new(0, 0, 0, 0), "Out", "Linear")
                LineLabel:TweenPosition(UDim2.new(0, 0, 0.8, 0), "In", "Linear")

                wait(0.5)

                for i, Line in pairs(Lines:GetChildren())do
                    local Text = Line.Value

                    for i = 1, #Text do
                        LineLabel.Text = string.sub(Text, 1, i)
                        Sounds.Talk:Play()
                        if Skip == true then
                            Skip = false
                            LineLabel.Text = Text
                            break
                        end
                        if Exit == true then
                            break
                        end
                        wait(0.07)
                    end
                    if Exit == true then
                        Exit = false
                        break
                    end
                    repeat wait() until Skip == true or Exit == true
                    Skip = false
                end

                Exit = false
                Skip = false

                PromptLabel:TweenSize(UDim2.new(0, 0, 0, 0), "Out", "Linear")
                LineLabel:TweenPosition(UDim2.new(0, 0, 1.2, 0), "In", "Linear")

                wait(0.5)

                Chatting = false
                Detected = false
            end
        end
    end
end)






RunService.RenderStepped:Connect(function()


    if Detected == false and Chatting == false then
        for i, NPC in pairs(NPCS:GetChildren())do
            local Humanoid = NPC:FindFirstChild("Humanoid")
            local HMR = NPC:FindFirstChild("HumanoidRootPart")

            if Humanoid and HMR then
                if (HMR.Position - CharHMR.Position).magnitude < 15 then
                    Detected = true
                    DetectedNPC = NPC
                    PromptLabel:TweenSize(UDim2.new(0, 60, 0, 60), "In", "Linear")
                    print("NPC.Name")
                end
            end

        end
    end

    if Detected == true and Chatting == false then
        local Humanoid = NPCS:FindFirstCHild("Humanoid")
        local HMR = NPCS:FindFirstCHild("HumanoidRootPart")

        if Humanoid and HMR then
            if (HMR.Position - CharHMR.Position).magnitude < 15 then
                Detected = false
                DetectedNPC = nil
                PromptLabel:TweenSize(UDim2.new(0, 0, 0, 0), "Out", "Linear")
                print("No Longer Detected NPC")
            else 
                local WTSP = Camera:WorldToScreenPoint(HMR.Position)
                PromptLabel.Position = UDim2.new(0, WTSP.X, 0, WTSP.Y)
            end
        end
    end

    if Chatting == true then
    local Humanoid = NPCS:FindFirstCHild("Humanoid")
        local HMR = NPCS:FindFirstCHild("HumanoidRootPart")

        if Humanoid and HMR then
            Camera.CameraType = Enum.CameraType.Scriptable
            Camera.Cframe = Camera.Cframe:Lerp(HMR.CFrame * CFrame.new(-4, 4, -7) * CFrame.fromOrientation(math.rad(-20), math.rad(215), 0), 0.07)
        end
    else
        Camera.CameraType = Enum.CameraType.Custom
    end


end)
0
this was a follow up/update from another question in case you did not know. JMC0077 -4 — 4y
0
Posted this in the other thread after having another look: Not sure if this is the problem, but on line 144 you have "Chatting == fake" which should be "Chatting == false" vector3_zero 1056 — 4y
0
hahaha I thought I fixed that.. I have a lot of spelling errors from time to time on this script JMC0077 -4 — 4y
0
yeah it says on this script it is fixed JMC0077 -4 — 4y
View all comments (7 more)
0
not sure why it does not work though JMC0077 -4 — 4y
0
What is it supposed to do? vector3_zero 1056 — 4y
0
Change lines 162 and 163 to reference DetectedNPC rather than NCPS vector3_zero 1056 — 4y
0
You also might want to be checking if magnitude is greater than 15 on line 166, not less than vector3_zero 1056 — 4y
0
what does that mean JMC0077 -4 — 4y
0
also the detectednpc thing did not work JMC0077 -4 — 4y
0
ima post this again JMC0077 -4 — 4y

Answer this question