So this is a local script within StarterGui. This script works fine until the NPC dies and respawns back again when I press e within the distance BobsChat doesn't appear. Output and Developer console say nothing.
Is there a way for this to work when the NPC spawns back? Please help!, Many thanks for reading
local NPCChat = { [game.Workspace:WaitForChild("Bob").Torso] = { distance = 3, GUI = game.ReplicatedStorage.BobsChat } } local player = game.Players.LocalPlayer local mouse = player:GetMouse() mouse.KeyDown:connect(function(key) if key == "e" then for NPC, properties in pairs(NPCChat) do if player.Character and (player.Character.Torso.Position - NPC.Position).magnitude < properties.distance and not player.PlayerGui:FindFirstChild(properties.GUI.Name) then properties.GUI:Clone().Parent = player:FindFirstChild("PlayerGui") end end end end)