How to make "E" proximity trigger visuals

It actually uses the Head of the character I believe.

You would use RunService’s events to handle the loop of checking distance on client. Once it’s close enough, run a function within the loop after the client is close enough and debounce other inputs in the loop. Exiting the distance would do the opposite.

The function that is ran should handle the visuals, by turning on the BillboardGui(and eventual animations) before and after.

@WaterJamesPlough Seems about right, I just re-read it and it was the head. The camera seems to be mounted to the head anyways, would not use HumanoidRootPart if you want the experience as the best for the user.

i am confused anyway can you tell me wat were the problems in my script?

Try parent your textlabel to a billboard gui, it might work if you do that? c:

and how do i fix them becuase i am a new scripter

as i saw in the video there was no billboard gui

You’ll have to add in one then.

this was the video i saw https://www.youtube.com/watch?v=tAfqnPn6XDk&t=1299s

You are using a normal server script, correct? If that’s so, you should split the script into a LocalScript and the normal script itself.

The LocalScript is responsible for:

  • Visuals
  • Distance check for visuals

The normal script:

  • Verifying distance(sanity checks)
  • Triggering dialogue for player

i am using local script not server script

You would use one of RunService’s functions or events:

Connect functions to events(or use the callback) to keep checking distance by using Player:DistanceFromCharacter(randomNPCPart).

The structure is unreadable in your script, so I have no clue unless you clean it a little.

i am using render stepped see the script

-\\ NPC Chat System: GUI Usage Tweening Camera Manipulation, Variabe Switching




--\\ Services

local RunService = game:GetService("RunService")
local UIS = game:GetService("UserInputService")
local Players = game:GetService("Players")




--\\ Main Variables

local DetectedNPC = nil
local Detected = false
local Chatting = false
local Skip = false
local Exit = false




--\\ Player

local Player = Players.LocalPlayer
local Camera = game.Workspace.CurrentCamera

local Gui = script.Parent
local Sounds = Gui.Sounds
local PromptLabel = Gui.PromptLabel
local LineLabel = Gui.LineLabel




--\\ Character

local Character = Player.Character or Player.CharacterAdded:Wait()
local CharHMR = Character:WaitForChild("HumanoidRootPart")




--\\ NPC

local NPCS = game.Workspace:WaitForChild("NPCS")




--\\ Functions

UIS.InputBegan:Connect(function(Input)
	if Input.KeyCode == Enum.KeyCode.X then
		if Chatting == true then
			Skip = true
			Sounds.Click:Play()
		end

	end
end)

UIS.InputBegan:Connect(function(Input)
	if Input.KeyCode == Enum.KeyCode.Z then
		if Chatting == true then
			Exit = true
			Sounds.Click:Play()
		end

	end
end)

UIS.InputBegan:Connect(function(Input)
	if Input.KeyCode == Enum.KeyCode.E then


		if Detected == true then
			local Lines = DetectedNPC:FindFirstChild("Lines")

			if Lines then
				Sounds.Click:Play()

				Chatting = true
				Detected = false

				LineLabel.Text = " "

				PromptLabel:TweenSize(UDim2.new(0, 0, 0, 0), "In", "Linear", 0.2)
				PromptLabel:TweenPosition(UDim2.new(0, 0, 0.8, 0), "In", "Linear", 0.2)

				wait(0.5)

				for i, Line in pairs(Lines:GetChildren()) do
					local Text = Line.Value

					for i = 1, #Text do
						LineLabel.Text = string.sub(Text, 1, i)
						Sounds.Talk:Play()
						if Skip == true then
							Skip = false
							LineLabel.Text = Text
							break
						end
						if Exit == true then
							break
						end
						wait(0.07)
					end
					if Exit == true then
						Exit = false
						break
					end
					repeat wait() until Skip == true or Exit == true
					Skip = false
				end

				Exit = false
				Skip = false

				PromptLabel:TweenSize(UDim2.new(0, 0, 0, 0), "Out", "Linear", 0.2)
				PromptLabel:TweenPosition(UDim2.new(0, 0, 1.2, 0), "Out", "Linear", 0.2)

				wait(0.5)

				Chatting = false
				Detected = false
			end			
		end
	end
end)




--\\ Main Loop

RunService.RenderStepped:Connect(function()


	if Detected == false and Chatting == false then
		for i, NPC in pairs(NPCS:Getchildren()) do
			local Humanoid = NPC:FindFirstChild("Humanoid")
			local HMR = NPC:FindFirstChild("HumanoidRootPart")

			if Humanoid and HMR then
				if (HMR.Position - CharHMR.Position).magnitude < 15 then
					Detected = true
					DetectedNPC = NPC
					PromptLabel:TweenSize(UDim2.new(0, 60, 0, 0), "Out", "Linear", 0.2)
					print(DetectedNPC.Name)
				end
			end
		end
	end

	if Detected == true and Chatting == false then
		local Humanoid = DetectedNPC:FindFirstChild("Humanoid")
		local HMR = DetectedNPC:FindFirstChild("HumanoidRootPart")

		if Humanoid and HMR then
			if (HMR.Position - CharHMR.Position).magnitude > 15 then
				Detected = false
				DetectedNPC = nil
				PromptLabel:TweenSize(UDim2.new(0, 0, 0, 0), "Out", "Linear", 0.2)
				print("NPC No longer detected.")
			else
				local WTSP = Camera:WorldToScreenPoint(HMR.Position)
				PromptLabel.Position = UDim2.new(0, WTSP.X, 0, WTSP.Y)
			end
		end	
	end
	
	if Chatting == true then
		local Humanoid = DetectedNPC:FindFirstChild("Humanoid")
		local HMR = DetectedNPC:FindFirstChild("HumanoidRootPart")

		if Humanoid and HMR then
			Camera.CameraType = Enum.CameraType.Scriptable
			Camera.CFrame = Camera.CFrame:Lerp(HMR.CFrame * CFrame.new(-4, 4, -7) * CFrame.fromOrientation(math.rad(-20), math.rad(215), 0), 0.07)
		end
	else
		Camera.CameraType = Enum.CameraType.Custom
	end
	
end)

You mention there are errors but did not declare exactly what errors they are. Could you elaborate that?

i got many errors and i was confused but i do have a pic of one of them

It doesn’t help if you don’t provide any of the errors or thoroughly debug your code. Also, it would better if you narrowed your code down, so we can work with something rather then 200 lines.

https://gyazo.com/baf1028260ca98e2fbdd0432e096f900

Sort your code again, properly, that the scopes(indenting) align rather than spreading out. You may or may not have missed or accidentally overshot an extra end somewhere, depending on where the scope started.

Try not reply in smaller messages, reply in one single bulk of message next time.

You can just use ProximityPrompt. Proximity Prompts | Documentation - Roblox Creator Hub