Locally hiding all ProximityPrompts

Been on & off trying for a couple weeks to come up with an efficient way to locally hide prompts in my vehicle game, came up with a lazy first solution just so I could get it out of the way, and test other things: every time humanoid.Sit changes, find all proximity prompts in workspace with a GetDescendants() which obviously isn’t too efficient, but I don’t think it’s a horrible approach? I eventually cleaned it up to being: initially, pass all prompts to new players from the server to their clients, with a remoteevent, then append each prompt in each newly spawned car to that list of prompts and trigger all clients to hide/show the rest of those according to the status of their humanoid.Sit.
it goes like:
function HidePrompts(prompts)
for I,v in pairs(prompts) do
v.Enabled = humaoid.Sit
v:getpropertychangedsignal(“Enabled”):Connect(function()
v.Enabled = humanoid.Sit (this function exists to handle other players sitting/standing, triggering their prompts to show for others when they don’t need to. each prompt has a hide/show script inside, is that needed?)
end)
end
And I changed this because I kept getting stack overflow errors (don’t know why, didn’t seem to be the problem.)
anyways, now the current iteration uses tags, each prompt is tagged and now this is what the whole script looks like. The problem right now is I get this weird memory thing going on with it. Every player can have two cars out, at most. So there’s a base number of like 60 prompts over the map, plus however many are in spawned cars. It starts off taking like 0.002mb of memory but easily adds 1mb per new car regardless of whether they still exist or not. I think the loop in hideprompts() is the problem because it keeps listening for property changed signals for EACH prompt, EAC time the function is called, and thus, each time you sit or stand? I think this is actually a really elementary problem, I promise I’m not that ametuer but I haven’t pressed myself to solve this phenomenon before lol.


player = game.Players.LocalPlayer
Prompts_ = game.ReplicatedStorage:WaitForChild("_Events"):WaitForChild("Prompts_")

CollectionService = game:GetService("CollectionService")
prompts = CollectionService:GetTagged("Prompts")

if player.Character == nil then
	player:GetPropertyChangedSignal("Character"):Connect(function()
		char = player.Character

	end)
else
	char = player.Character

end

function HidePrompts(humanoid)
pcall(function()
	for i=1,#prompts do
			prompts[i].Enabled = not(humanoid.Sit)
			prompts[i]:GetPropertyChangedSignal("Enabled"):Connect(function()
				if prompts[i] ~= nil then
					prompts[i].Enabled = not(humanoid.Sit)
				end
			end)


		end
	end)
	

end


local humanoid = char:WaitForChild("Humanoid")
prompts = CollectionService:GetTagged("Prompts")

Prompts_.OnClientEvent:Connect(function(Prompts_Inworld) --triggers every time a new car is spawned 

	prompts = Prompts_Inworld
	HidePrompts(humanoid)
end)


humanoid:GetPropertyChangedSignal("Sit"):Connect(function()
	prompts = CollectionService:GetTagged("Prompts")
	HidePrompts(humanoid)

end)

Any better approaches? Am I right about the problem?

1 Like