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

How to make multiple parts and they all have the same value?

Asked by 2 years ago

So i am trying to make like a tool that destroys parts when clicked an amount of times and i have a part named MinePart but i have like 50 of them with the same name the same intvalue because its like a mining game but it only shows up for 1 of the parts and not any others i really need help i have no idea what to do heres my script:

local Tool1 = script.Parent local Tool1Damage = script.Parent.Folder.Tool1Damage Tool1Damage.Value = 1

local MinePart = game.Workspace:FindFirstChild("MinePart") local Health = MinePart.Folder:FindFirstChild("Health") Health.Value = 15

Tool1.Equipped:Connect(function(mouse) mouse.Button1Down:Connect(function() if mouse.Target and mouse.Hit then if mouse.Target == MinePart then Health.Value = Health.Value - Tool1Damage.Value if Health.Value <= 0 then MinePart:Destroy() end end end end) end)

0
I think your problem is using the ":FindFirstChild" event. This script will only apply to the first part named "MinePart". Use ":GetChildren()" instead? Zsows77 2 — 2y

1 answer

Log in to vote
0
Answered by
Puppynniko 1059 Moderation Voter
2 years ago

you would want to make a identifier if the block is a block or just part of the map after that just check if the part has the identifier

local Tool1 = script.Parent local Tool1Damage = script.Parent.Folder.Tool1Damage Tool1Damage.Value = 1

local MinePart = game.Workspace:FindFirstChild("MinePart") local Health = MinePart.Folder:FindFirstChild("Health") Health.Value = 15

Tool1.Equipped:Connect(function(mouse) mouse.Button1Down:Connect(function() if mouse.Target and mouse.Hit then if mouse.Target:FindFirstChild("Identifer") then --if it can find the identifer then set the part to Mouse.Target
local Part = Mouse.Target
Health.Value = Health.Value - Tool1Damage.Value 
if Health.Value <= 0 then Part:Destroy()
 end
 end 
end 
end)
 end)
0
what would the identifer be like a part or something and would you name the identifer "identifer" and what Part are you reffering to when you put local Part = mouse.Target iamnotcool235_s 27 — 2y
0
the identifer make sure it is a part not just any map parts thats not suppose to be destroyed Puppynniko 1059 — 2y
Ad

Answer this question