I have been trying to create an NPC interaction system, where a mini GUI pops up stating ‘Press E to interact with NPC.’ It all works - but only for one NPC. The mini GUI pop-up for all the other NPC’s are not functioning. There is nothing popping up in the Output which is really annoying. Here’s the LocalScript plus a video:
local UserInputService = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local isinrageof = 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 isinrageof ~= nil and not istalking then
if ischatting == false then
line = 1
ischatting = true
dialogues = require(isinrageof.Lines)
Player.Character.Humanoid.WalkSpeed = 0
script.Parent.DialogueFrame.Dialogue.Text = ""
script.Parent.DialogueFrame.NPCName.Text = isinrageof.Name
script.Parent.DialogueFrame:TweenPosition(UDim2.new(0.099,0,0.809,0), "Out", "Back", .2, true)
script.Parent.Keybind:TweenPosition(UDim2.new(0.375,0,1.1,0),"Out","Back",.3)
script.Parent.Keybind.Visible = false
script.Parent.KeybindEnabled.Value = false
wait(.4)
local CurLine = dialogues[line]
istalking = true
for i=1,#CurLine[1] do
script.Parent.DialogueFrame.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.DialogueFrame:TweenPosition(UDim2.new(0.099,0,1.2,0), "Out", "Back", .2, true)
script.Parent.Keybind:TweenPosition(UDim2.new(0.375,0,0.877,0),"Out","Back",.3)
script.Parent.Keybind.Visible = true
script.Parent.KeybindEnabled.Value = true
Player.Character.Humanoid.WalkSpeed = 16
dialogues = nil
ischatting = false
else
local CurLine = dialogues[line]
istalking = true
for i=1,#CurLine[1] do
script.Parent.DialogueFrame.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
for i,v in pairs(workspace.NPCs:GetChildren()) do
if(Player.Character.HumanoidRootPart.Position-v.Torso.Position).magnitude <= 6 then
isinrageof = v
script.Parent.Keybind:TweenPosition(UDim2.new(0.375,0,0.877,0),"Out","Back",.3)
script.Parent.Keybind.TextLabel.Text = "Press 'E' to interact with "..v.Name.."."
else
script.Parent.Keybind:TweenPosition(UDim2.new(0.375,0,1.1,0),"Out","Back",.3)
end
end
end
end