|
| 07 Jun 2017 09:42 PM |
What I'm trying to do it locate a specific part out of a list of 20 models.
So in ReplicatedStorage, there's a Model called BasicMapCars the has 20 models inside of it. In each of those 20 models, there's a part called 'Bumper' that I'm trying to isolate.
How would I do this?
|
|
|
| Report Abuse |
|
|
| |
|
legosweat
|
  |
| Joined: 18 Aug 2015 |
| Total Posts: 42 |
|
|
| 07 Jun 2017 09:55 PM |
This is how you locate a individual part. I think this is what you want.
local rStorage = game:GetService("ReplicatedStorage") -- Get the service
local mapCars = rStorage:WaitForChild("BasicMapCars") -- waits for this model to be there -- WaitForChild: this waits for it in case it hasn't loaded in yet
local Bumper = mapCars:WaitForChild("Bumper") -- Wait for model/part in mapCars
-- END
Another way to locate items:
bumper = game.ReplicatedStorage.BasicMapCars.Bumper
but top one is more efficient |
|
|
| Report Abuse |
|
|
legosweat
|
  |
| Joined: 18 Aug 2015 |
| Total Posts: 42 |
|
|
| 07 Jun 2017 09:56 PM |
| Just realized I read it wrong, hold on. |
|
|
| Report Abuse |
|
|
legosweat
|
  |
| Joined: 18 Aug 2015 |
| Total Posts: 42 |
|
|
| 07 Jun 2017 10:04 PM |
local rStorage = game:GetService("ReplicatedStorage")
local mapCars = rStorage:WaitForChild("BasicMapCars")
local getCars = mapCars:GetChildren() -- Makes table of children
--To get an individual bumper (in this case 5th one down) local carBumper = getCars[5]:WaitForChild("Bumper")
--To go through all bumpers (for making connections, etc.) for i,v in pairs(getCars) do local bumper = v:FindFirstChild("Bumper") if bumper then -- Checks for bumper -- This code fires when bumper has been found -- the bumper of the car is classified as 'bumper' -- Do stuff to part -- Example: bumper.BrickColor3 = Color3.new("Some Color") end end
|
|
|
| Report Abuse |
|
|
|
| 07 Jun 2017 10:11 PM |
Give me a minute to put this in place. I'll let you know once I'm done.
|
|
|
| Report Abuse |
|
|
WildGuest
|
  |
| Joined: 28 Feb 2010 |
| Total Posts: 647 |
|
|
| 07 Jun 2017 10:15 PM |
I put this on your other thread, not discrediting the other guy but I figured I'd post it here too.
for i,v in pairs(game.ReplicatedStorage.BasicMapCars:GetChildren()) do local Bumper = v:FindFirstChild("Bumper") --Do whatever to bumper here for instance --Bumper:Remove() end
|
|
|
| Report Abuse |
|
|
|
| 07 Jun 2017 10:15 PM |
Okay, I'm not sure if this is possible, but I want it to fire this:
function touch(hit) local boom = Instance.new("Explosion") local fire = Instance.new("Fire") if hit.Parent.Name == "Car" then if script.Parent.Velocity.Magnitude > 200 then hit:BreakJoints() fire.Parent = hit boom.Parent = hit boom.BlastPressure = 500000 boom.BlastRadius = 1 boom.Position = hit.Position elseif script.Parent.Velocity.Magnitude > 50 then hit:BreakJoints() end end end
script.Parent.Touched:connect(touch)
if bumper is found. Would that work? These cars are being pulled out of ReplicatedSotrage into the Workspace when called by a GUI.
|
|
|
| Report Abuse |
|
|
| |
|
WildGuest
|
  |
| Joined: 28 Feb 2010 |
| Total Posts: 647 |
|
|
| 07 Jun 2017 10:44 PM |
Put that script in all of the bumpers and bring the bumpers out one by one when needed.
|
|
|
| Report Abuse |
|
|
|
| 07 Jun 2017 11:23 PM |
That what I was trying to avoid. The script I put into was already in all the bumpers (and worked), but I was trying to get one script to handle them all.
|
|
|
| Report Abuse |
|
|
WildGuest
|
  |
| Joined: 28 Feb 2010 |
| Total Posts: 647 |
|
|
| 07 Jun 2017 11:44 PM |
for i,v in pairs(game.ReplicatedStorage.BasicMapCars:GetChildren()) do local Bumper = v:FindFirstChild("Bumper") Bumper.Touched:connect(function(hit) local boom = Instance.new("Explosion") local fire = Instance.new("Fire") if hit.Parent.Name == "Car" then if Bumper.Velocity.Magnitude > 200 then hit:BreakJoints() fire.Parent = hit boom.Parent = hit boom.BlastPressure = 500000 boom.BlastRadius = 1 boom.Position = hit.Position elseif Bumper.Velocity.Magnitude > 50 then hit:BreakJoints() end end end) end
|
|
|
| Report Abuse |
|
|
|
| 08 Jun 2017 12:05 AM |
It seems good, but the Output window says
attempt to index local 'Bumper' (a nil value)
|
|
|
| Report Abuse |
|
|
WildGuest
|
  |
| Joined: 28 Feb 2010 |
| Total Posts: 647 |
|
|
| 08 Jun 2017 12:22 AM |
for i,v in pairs(game.ReplicatedStorage.BasicMapCars:GetChildren()) do local Bumper = v:FindFirstChild("Bumper") if Bumper ~= nil then Bumper.Touched:connect(function(hit) local boom = Instance.new("Explosion") local fire = Instance.new("Fire") if hit.Parent.Name == "Car" then if Bumper.Velocity.Magnitude > 200 then hit:BreakJoints() fire.Parent = hit boom.Parent = hit boom.BlastPressure = 500000 boom.BlastRadius = 1 boom.Position = hit.Position elseif Bumper.Velocity.Magnitude > 50 then hit:BreakJoints() end end end end) end
|
|
|
| Report Abuse |
|
|
|
| 08 Jun 2017 01:34 AM |
It didn't work.
Even when I fixed your error on the parenthesis.
for i,v in pairs(game.ReplicatedStorage.BasicMapCars:GetChildren()) do local Bumper = v:FindFirstChild("Bumper") if Bumper ~= nil then Bumper.Touched:connect(function(hit) local boom = Instance.new("Explosion") local fire = Instance.new("Fire") if hit.Parent.Name == "Car" then if Bumper.Velocity.Magnitude > 200 then hit:BreakJoints() fire.Parent = hit boom.Parent = hit boom.BlastPressure = 500000 boom.BlastRadius = 1 boom.Position = hit.Position elseif Bumper.Velocity.Magnitude > 50 then hit:BreakJoints() end end end) end end
|
|
|
| Report Abuse |
|
|