local ammoBox = workspace.Box_Ammo
local GUI = ammoBox.GUI
local Label = GUI.TextLabel
local player = game.Players.LocalPlayer
local magnitude = (player.Character.HumanoidRootPart.Position - ammoBox.Position).Magnitude
local uim = game:GetService("UserInputService")
local x = true
coroutine.wrap(function()
while wait() do
magnitude = (player.Character.HumanoidRootPart.Position - ammoBox.Position).Magnitude
math.floor(magnitude)
end
end)()
coroutine.wrap(function()
while wait() do
if magnitude <=10 then
x = false
GUI.Enabled = true
else
x = true
GUI.Enabled = false
end
end
end)()
uim.InputBegan:Connect(function(key,gameproc)
if x == false then
if key.KeyCode == Enum.KeyCode.F and not gameproc then
game.ReplicatedStorage.Events.ammoBox:FireServer(ammoBox,gun)
end
end
end)
Right, this script is supposed to delete a 'ammoBox' when you press F, and are under 10 studs away from the box. However;
There is more than one ammoBox, and this does it to random boxes. And I don't want to create a new localscript for every single box that I put in. I want it to recognize a box when a player is near it. But I don't know how.
Any help is very appreciated. please leave anything helpful.
ty for reading <3

1 comment
ty, but I need it to work unanimously with all parts that are . named ammoBox