For loop only working for one Part / Object

So awhile ago i made a post about my seat not sitting the humanoid. It has been fixed, but now my script only functions for one seat, and not my other seats

The video shows my issue

This is my code;


local Seats = script.Parent.Seats

local ProximityPromptService = game:GetService("ProximityPromptService")


for _ , v in ipairs(Seats:GetChildren()) do
	
	Seat = v
	
	SeatPrompt = Seat:FindFirstChild("SeatPrompt")

	
end
	

Seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	
	if Seat.Occupant ~= nil then
		
		SeatPrompt.Enabled = false
		
	elseif Seat.Occupant == nil then
		
		SeatPrompt.Enabled = true
		
	end
	
end)

ProximityPromptService.PromptTriggered:Connect(function(SeatPrompt , plr)

	local Humanoid = plr.Character:FindFirstChildOfClass("Humanoid")
	
	Seat:Sit(Humanoid)
	
	print("Test")

end)

As usual, any help would be greatly appreciated

I think I found the problem when you declare the seat every iteration, it will only be set the one seat. All the following code is only doing it for the last assignment of the variable seat. Try putting the rest of the code inside of the loop, so it knows that every seat should have it.

Hi, again, it does only one variable in the for loop because only the last value counts and ur using ipairs thats why its always the same seat.
Can i see where the prompt is located in the explorer?

Lol, we had the same idea arotje, while I was typing you posted.

1 Like

there are 4 seats each with prompts inside

StudioIssueImg

I tried doing that, but then the sit function does not work, it does not recognize v as a seat when i attempt it

You could try it without the for loop, just to see if it works.

After doing some experimenting, I found that creating a new proximity prompt instance when the loop runs solves the problem I’ve been having, thanks everyone for the help and responses

1 Like

This is probably because of the priority of the prompts.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.