Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make a script recognize a certain part that shares the same name as others?

Asked by 5 years ago
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 answer

Log in to vote
0
Answered by 5 years ago

Hey, this probably won't work because I'm an idiot at scripting but maybe you could change the part name slightly.

Let's say there's 2 'parts', so you could change it to Part1 and Part2.

Or if you're doing it in the script, and the part has a Parent like Workspace > House > Part you could say it's Parent if you're doing something specific, that way if you're talking about a part in something, you won't change something else random with the same name.

Yeah ..you can try it but it probably won't work because remember I'm really poop at scripting.

0
ty, but I need it to work unanimously with all parts that are . named ammoBox userdetail 1 — 5y
Ad

Answer this question