How can I make it so that when a player presses shift near an ammo table, it reloads their gun for them... I'm not sure how to check if an ammo table is within a certain range, especially when there are multiple ammo tables in workspace, with the same name. Would I use the magnitude between the player and the ammo table?
function ReloadAmmo() local torso = script.Parent.Parent.Torso local list = game.Workspace:FindFirstChild("AmmoBox") local dist = 50 if (torso.Position - list.Main.Position).magnitude < dist then torso.Anchored = true wait(2) clipleft.Value = clipsize clipsleft.Value = clips torso.Anchored = false end end
ReloadAmmo is called when the player presses the shift key, All I need to do now to fix it is find out how to store all the ammo tables in an array and cycle through them, checking to see if any of them are in range, so that I can have multiple ammo tables in a single map. Thanks Perci and Goulstem for your help with this!