How do i make this script constantly Update?

Hello, I’m trying to make this proximity Prompt only enable if the player is facing its direction and it works but there’s 1 problem, it only updated when the player moves again after it disables or enables, how do i make it update constantly?

local char = player.Character
local RunService = game:GetService("RunService")

RunService.RenderStepped:Connect(function(step)
	local ray = Ray.new(char.Head.Position, ((char.Head.CFrame + char.Head.CFrame.LookVector * 2) - char.Head.Position).Position.Unit * 60)
	local ignoreList = char:GetChildren()

	local hit, pos = game.Workspace:FindPartOnRayWithIgnoreList(ray, ignoreList)
	
	if hit then
		workspace.FaceProx.ProximityPrompt.Enabled = false
		if hit.Name == "FaceProx" then
			workspace.FaceProx.ProximityPrompt.Enabled = true
			print("HittingWall")
			else
			if not hit then
				print("HitNothing")
				workspace.FaceProx.ProximityPrompt.Enabled = false
			end
		end	
	end
end)
1 Like

Just put it in a constant loop that runs the script every certain amount of time

while true do
  -- your script here
  wait() -- just put the certain amount of time you want between each check, if you don't add a "wait" then the script will output an error
end
2 Likes

dident seem to update it for me, i still had to move for it to update

hmmm, i’m not really sure then, the only way i know to make a script update is with a loop, i’ll try to look into it and find another way

That script is actually already updating all the time due to it being inside of the function connected to the RunService Renderstepped event.

However, it terminates early if the ray doesn’t have a hit. However, if the ray does have a hit and it’s not your FaceProx then it disables the UI. So yes it is running.

My recommendation would be to check if the player’s lookVector matches the FaceProx’s lookVector inversed. I believe there’s probably some trigonometry you can use for this. But I’m not good at math at all. Using the Ray like that will cause it to only work if you have a hit, and that hit is “FaceProx” so it’s not exactly accurate and more finicky than ever.

Edit: Does the require line of sight option not work for you in this situation with proximity prompts?

if hit and hit.Name == "FaceProx" then
	workspace.FaceProx.ProximityPrompt.Enabled = true
	print("HittingWall")
else
	print("HitNothing or wrong wall")
	workspace.FaceProx.ProximityPrompt.Enabled = false
end

or

workspace.FaceProx.ProximityPrompt.Enabled = hit and hit.Name == "FaceProx" or false

Well I wasn’t gonna use it originally for proximity prompts, I was gonna make it where if the player faces a certain place something happens but I tested with a proximity prompt

I wanted the proximity prompt more realistic, if ur in third person not facing it u can still use it

I think its due to the Ray you made