So recently I've been working on something and I was doing fine but I have came to a stop because of a blockage, rendering me unable to continue.
If anyone can possibly help, it would be VERY appreciated.
Here is my current script:
--[[ Variables ]]-- local plr = game.Players.LocalPlayer char = workspace:WaitForChild(tostring(plr.Name)) local ID = workspace:WaitForChild("Interactive_Doors") local II = workspace:WaitForChild("Interactive_Items") local Available = false local item --[[ Functions ]]-- function Use() if Available == true then print("picked up item") if item then item.Parent = plr end end end --[[ CONTROL BINDING ]]-- local controls = game:GetService("ContextActionService") controls:BindAction("Interact", Use, false, Enum.KeyCode.E) for i,v in ipairs(II:GetChildren()) do while true do if (char.Torso.Position - v.Position).magnitude <= 5 then Available = true item = v else Available = false item = nil end wait() end end
At the bottom for the last bit of code, you can see I am using a while true do loop to continue checking to see if a player is near certain parts that are in a folder called "Interactive_Items".
I was wondering if there was a way to make this better or more efficient without using a loop, or at least a BETTER way of doing it with loops?
The reasoning of asking this is because I have two folders for two different types of interactions. But the issue I seek to solve is that when it goes into that loop, it gets stuck on those lines making it so I can't do a second ipairs loop for the other folder.
If you don't understand what I'm trying to explain, just let me know and I'll try my best to explain again.
Thanks again! :)