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

Talking NPC scripts aren't working (works in Studio, not in-game), how can I fix?

Asked by 6 years ago

This script works in ROBLOX Studio, but not in actual in-game form. Just wondering if there really is a problem with the script, or if it's just some plugin I own that's ruining it in some way.

Local Script (StarterGui>ScreenGui)

local UserInputService = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Character = Player.Character
local isinrangeof = nil
local ischatting = false
local line = 1
local istalking = false
local dialogues = nil

local function onInputBegan(input,gameProcessed)
    if input.UserInputType == Enum.UserInputType.Keyboard then
        local keyPressed = input.KeyCode
        if keyPressed == Enum.KeyCode.E then
            if isinrangeof ~= nil and not istalking then
                if ischatting == false then
                    line = 1
                    ischatting = true
                    dialogues = require(isinrangeof.Lines)
                    Character.Humanoid.WalkSpeed = 0
                    script.Parent.DialogueHolder.Dialogue.Text = ""
                    script.Parent.DialogueHolder:TweenPosition(UDim2.new(.5,0,.875,0),Enum.EasingDirection.Out,Enum.EasingStyle.Back,.5,true)
                    wait(.5)
                    local CurLine = dialogues[line]
                    istalking = true
                    for i = 1,#CurLine[1] do
                        script.Parent.DialogueHolder.Dialogue.Text = string.sub(CurLine[1],0,i)
                        wait(CurLine[2])
                    end
                    if CurLine[3] then
                        CurLine[3]()
                    end
                    istalking = false
                    line = line +1
                else
                    local CurLine = dialogues[line]
                    if line > #dialogues then
                        script.Parent.DialogueHolder:TweenPosition(UDim2.new(.5,0,1.5,0),Enum.EasingDirection.Out,Enum.EasingStyle.Back,.5,true)
                        Character.Humanoid.WalkSpeed = 16
                        dialogues = nil
                        ischatting = false
                    else
                        local CurLine = dialogues[line]
                        istalking = true
                        for i = 1,#CurLine[1] do
                            script.Parent.DialogueHolder.Dialogue.Text = string.sub(CurLine[1],0,i)
                            wait(CurLine[2])
                        end
                        if CurLine[3] then
                            CurLine[3]()
                        end
                        istalking = false
                        line = line +1
                    end
                end
            end
        end
    end
end

UserInputService.InputBegan:connect(onInputBegan)

while true do
    wait()
    if ischatting == false then
        isinrangeof = nil
        for i,v in pairs(workspace.NPCS:GetChildren()) do
            if(Character.HumanoidRootPart.Position-v.HumanoidRootPart.Position).magnitude <= 5 then
                isinrangeof = v
            end
        end
    end
end

Module Script (Workspace>Folder>Model)

local NPCLines = {
    {"Text",.05,nil},


    }

return NPCLines

Answer this question