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

Trying to make a talking npc when you press e however script doesnt work?

Asked by 5 years ago

local UserInputService = game:GetService("UserInputService") local Player = game.Players.LocalPlayer local isinrageof = nil local ischatting = false local line = 1 local istalking = false local dialouges = nil

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

UserInputService.InputBegan:connect(onInputBegan)

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

0
Use code blocks and show the error code. YTRaulByte 389 — 5y
0
USE CODE BLOCKS XDDDD Enomphia 39 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

This isn't an answer, just doing it to help anyone else who wants to give one:

local UserInputService = game:GetService("UserInputService") 

local Player = game.Players.LocalPlayer 

local isinrageof = nil 
local ischatting = false 
local line = 1 
local istalking = false 
local dialouges = nil

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

UserInputService.InputBegan:connect(onInputBegan)

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

Answer this question