Code:
local eToContinueGui = game.ReplicatedStorage.UI.BillboardGui
local players = game:GetService("Players")
local runService = game:GetService("RunService")
local userInputService = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")
local shown = false
local epressed = false
local dialogueText = script.Parent.Frame.Frame.TextLabel
local ImageLabel = script.Parent.Frame.Frame.ImageLabel
local pictures = {
"rbxassetid://5794645261", --Onyiistarr
"rbxassetid://5781715416" --It's me no name
}
local ItsMeNoNamedialogues = {
"Ayy Dude! It's almost Halloween! Let's celebrate!",
"Feel Free to Visit anytime :D",
"Did you know that there is gonna be a full Halloween Update (Event) by the end of October?",
"It's kinda spooky out here, maybe playing some obbies will help set up the mood"
}
local OnyiiDialogues = {
"Hey, Happy Halloween mate! Wanna buy some costumes, go to my homestore, link is in the description in the game :D",
"Hi again, Did you know Im a growing youtuber, Can you sub to me mate? My channel is OnyiiStarr, Thanks Mate :D",
"Hello"
}
local dialogueTweenInfo = TweenInfo.new(1, Enum.EasingStyle.Elastic, Enum.EasingDirection.InOut, 0, false, 0)
local dialogueframe = script.Parent.Frame
local openTweenService = TweenService:Create(dialogueframe, dialogueTweenInfo, {Position = UDim2.new(0.25, 0,0.781, 0)})
local closedTweenService = TweenService:Create(dialogueframe, dialogueTweenInfo, {Position = UDim2.new(0.25, 0, 1.1, 0)})
print("inputed E")
local closestNPC,gui,currentNPC
local character = players.LocalPlayer.Character
userInputService.InputBegan:Connect(function(input)
print(closestNPC)
if input.KeyCode == Enum.KeyCode.E then
print("Closest NPC")
if epressed == false then
print("e")
if closestNPC == "ItsMeNoName" then
print('bbruh')
epressed = true
shown = true
print("E")
local ItsMedialogue = ItsMeNoNamedialogues[math.random(1, #ItsMeNoNamedialogues)]
dialogueText.Text = ItsMedialogue
openTweenService:Play()
wait(5)
shown = false
closedTweenService:Play()
wait(1)
epressed = false
end
if closestNPC == "Onyiistarr" then
epressed = true
shown = true
local Onyidialogue = OnyiiDialogues[math.random(1, #OnyiiDialogues)]
dialogueText.Text = Onyidialogue
openTweenService:Play()
wait(5)
shown = false
closedTweenService:Play()
wait(1)
epressed = false
end
end
end
end)
local toggleGui = function(toggle)
if gui then
gui:Destroy()
gui = nil
end
if toggle == true then
gui = eToContinueGui:Clone()
gui.Parent = closestNPC:FindFirstChild("EPart")
end
end
runService.RenderStepped:Connect(function()
local maxDistance = 15
local newClosestNPC
for _, NPC in pairs(game.Workspace.NPC:GetChildren())do
if (NPC.EPart.Position - character.HumanoidRootPart.Position).magnitude <= maxDistance then
maxDistance = (NPC.EPart.Position - character.HumanoidRootPart.Position).magnitude
newClosestNPC = NPC
end
end
closestNPC = newClosestNPC
if closestNPC then
toggleGui(true)
return closestNPC
else
toggleGui(false)
end
end)
In this I wanted to achieve displaying the proper UI whenever the player talks to a NPC but my problem is that the if statement on closestNpc (line 51 and 66) is somehow not working, so to solve the problem I added a print system on every statement to see if it’s really going trough it, in the output it says:
this happened ofc whenever I go to the desired NPC, it says here the Closes NPC value is ItsMeNoName but the if statement is somehow not working, there no errors in the output
All Help is appreciated, thank you