generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Getting the part from the GetFullName()

Previous Thread :: Next Thread 
adoman is not online. adoman
Joined: 01 Sep 2010
Total Posts: 306
01 Jun 2016 06:53 PM
Say that I have..

t = {}

then a loop that adds the "FullName" of the part into each spot
(the directory for that part is the full name, the GetFullName())

next i want to get a reference to that part from the fullname
then make a loop to check to see if any of these parts are touched

Is there a way to : get a reference to that part from the fullname

because if so I know how to do the rest of the work.


Report Abuse
adoman is not online. adoman
Joined: 01 Sep 2010
Total Posts: 306
01 Jun 2016 06:57 PM
anyone have an idea??
Report Abuse
Skellobit is not online. Skellobit
Joined: 13 Apr 2016
Total Posts: 12758
01 Jun 2016 06:58 PM
I don't understand

Formerly ToxicDominator - add 17,509 posts | :(){:|:&};:
Report Abuse
Flux_Capacitor is not online. Flux_Capacitor
Joined: 07 Apr 2008
Total Posts: 45720
01 Jun 2016 07:01 PM
Don't add the FullName to begin with, add the actual reference to the part. It's better because you're not restricted if you have multiple objects with the same name in the same place.
Report Abuse
adoman is not online. adoman
Joined: 01 Sep 2010
Total Posts: 306
01 Jun 2016 07:02 PM
Here is an example of what i mean

array = {}
local parts = game.workspace.partfolder:GetChildren()

for i=1, #parts do
local partName = parts[i]:GetFullName()
table.insert(array, i, partName)
end

while true do
for i=1, #array do
array[i].Touched:connect(function(hit)

end
wait()
end
Report Abuse
adoman is not online. adoman
Joined: 01 Sep 2010
Total Posts: 306
01 Jun 2016 07:04 PM
Here is an example of what i mean

array = {}
local parts = game.workspace.partfolder:GetChildren()

for i=1, #parts do
local partName = parts[i]:GetFullName()
table.insert(array, i, partName)
end

while true do
for i=1, #array do
array[i].Touched:connect(function(hit) -- array[i].Touched fails because touched
-- is not valid with a name and that's why i would like to know how to get the part
-- from the GetFullName()
print(array[i].Name)
end
wait()
end
Report Abuse
Flux_Capacitor is not online. Flux_Capacitor
Joined: 07 Apr 2008
Total Posts: 45720
01 Jun 2016 07:05 PM
Why are you doing it like that? Why not just do this:


local function onTouched(hit)
-- do stuff
end

local parts = game.Workspace.partfolder:GetChildren()
for i = 1, #parts do
parts[i].Touched:connect(onTouched)
end
Report Abuse
Skellobit is not online. Skellobit
Joined: 13 Apr 2016
Total Posts: 12758
01 Jun 2016 07:05 PM
^ yeah that's what I was thinking...I still have no idea why OP is doing it that way

Formerly ToxicDominator - add 17,509 posts | :(){:|:&};:
Report Abuse
adoman is not online. adoman
Joined: 01 Sep 2010
Total Posts: 306
01 Jun 2016 07:05 PM
Alright flux but what type of data value is the actual object then ?
like what goes into the array??
Report Abuse
Flux_Capacitor is not online. Flux_Capacitor
Joined: 07 Apr 2008
Total Posts: 45720
01 Jun 2016 07:06 PM
userdata. Essentially it's just an object.
Report Abuse
adoman is not online. adoman
Joined: 01 Sep 2010
Total Posts: 306
01 Jun 2016 07:07 PM
Okay, I have 8 zombies. Iterate through those and get the BaseParts only.
How would I do that?
Report Abuse
Flux_Capacitor is not online. Flux_Capacitor
Joined: 07 Apr 2008
Total Posts: 45720
01 Jun 2016 07:07 PM
So you want to put all the BaseParts of each zombie into an array?
Report Abuse
adoman is not online. adoman
Joined: 01 Sep 2010
Total Posts: 306
01 Jun 2016 07:09 PM
correct, then check in a while loop if ANY are being touched
Report Abuse
adoman is not online. adoman
Joined: 01 Sep 2010
Total Posts: 306
01 Jun 2016 07:10 PM
that i can do though

for i=1, #allthings do
if (allthings[i]:IsA("BasePart")) then
table.insert(myarray, i, allthings[i]:GetFullName())
end
end
Report Abuse
Flux_Capacitor is not online. Flux_Capacitor
Joined: 07 Apr 2008
Total Posts: 45720
01 Jun 2016 07:12 PM
local allParts = {}

local function zombieTouched(zombie, hit)
print(hit.Name .. " hit zombie: " .. zombie.Name)
end

local zombies = game.Workspace.Zombies:GetChildren()
for idx = 1, #zombies do
local zombie = zombies[idx]
local parts = zombie:GetChildren()
for idx = 1, #parts do
parts[idx].Touched:connect(function(hit) zombieTouched(zombie, hit) end)
end
end
Report Abuse
Flux_Capacitor is not online. Flux_Capacitor
Joined: 07 Apr 2008
Total Posts: 45720
01 Jun 2016 07:13 PM
Oh yeah add 'if parts[idx]:IsA("BasePart") then' before the event connection
Report Abuse
adoman is not online. adoman
Joined: 01 Sep 2010
Total Posts: 306
01 Jun 2016 07:13 PM
what about this...



for i=1, #allthings do
if (allthings[i]:IsA("BasePart")) then
table.insert(myarray, i, allthings[i]) -- removed :GetFullName()
end
end
Report Abuse
Flux_Capacitor is not online. Flux_Capacitor
Joined: 07 Apr 2008
Total Posts: 45720
01 Jun 2016 07:14 PM
Yeah that'd put all the baseparts in the table. I gave you the full solution based on what you told me
Report Abuse
adoman is not online. adoman
Joined: 01 Sep 2010
Total Posts: 306
01 Jun 2016 07:14 PM
wait.. let me test this and see if it works....
Report Abuse
Flux_Capacitor is not online. Flux_Capacitor
Joined: 07 Apr 2008
Total Posts: 45720
01 Jun 2016 07:15 PM
You don't need to add them to a table:

local function zombieTouched(zombie, hit)
print(hit.Name .. " hit zombie: " .. zombie.Name)
end

local zombies = game.Workspace.Zombies:GetChildren()
for idx = 1, #zombies do
local zombie = zombies[idx]
local parts = zombie:GetChildren()
for idx = 1, #parts do
if parts[idx]:IsA("BasePart") then
parts[idx].Touched:connect(function(hit) zombieTouched(zombie, hit) end)
end
end
end
Report Abuse
adoman is not online. adoman
Joined: 01 Sep 2010
Total Posts: 306
01 Jun 2016 07:17 PM
here is the full code just so you can glance at it cause i have one more issue..




wait(4)

local running = false
zombieParts = {}
local zombiePartsCount = 1

local function startRound()
local zombies = game.Workspace.WaitingZombies:GetChildren()

-- move zombies to correct dirrectory
for i=1, #zombies do
zombies[i].Parent = game.Workspace.ActiveZombies.ZombieModels
end

wait(1)

-- collect all zombie parts before they move
local zombieModels = game.Workspace.ActiveZombies.ZombieModels:GetChildren()
for i=1, #zombieModels do
local zomparts = zombieModels[i]:GetChildren()
for i=1, #zomparts do
if (zomparts[i]:IsA("BasePart")) then
table.insert(zombieParts, zombiePartsCount, zomparts[i]) -- :GetFullName()
zombiePartsCount = zombiePartsCount + 1
end
end
wait(0.1)
end
wait(0.5)

-- main game loop
while #game.Workspace.ActiveZombies.ZombieModels:GetChildren() > 0 do

local zombieModels = game.Workspace.ActiveZombies.ZombieModels:GetChildren()

-- movement
for i=1, #zombieModels do
local pos = Vector3.new(9.5, 4.4, 155.7)
zombieModels[i].Humanoid:MoveTo(pos)
end

-- health check
for i=1, #zombieModels do
local zomlife = zombieModels[i].Humanoid.Health
if (zomlife == 0 or zomlife < 0) then
wait(.5)
zombieModels[i]:remove()
end
end

--collision check
for i=1, #zombieParts do
zombieParts[i].Touched:connect(function(hit)
if (hit.Name == "fallingLava") then
print(hit.Name)
end
end)
end

wait()
end

running = false
end

while true do
if (#game.Players:GetChildren() > 0) then
running = true
startRound()
end
wait()
end
Report Abuse
Flux_Capacitor is not online. Flux_Capacitor
Joined: 07 Apr 2008
Total Posts: 45720
01 Jun 2016 07:18 PM
You don't connect the Touched event in a loop, you do it once and every time the part is touched the function you gave it will fire.

Report Abuse
adoman is not online. adoman
Joined: 01 Sep 2010
Total Posts: 306
01 Jun 2016 07:19 PM
so then how can i connect the touched event to like 35 parts?
Report Abuse
Flux_Capacitor is not online. Flux_Capacitor
Joined: 07 Apr 2008
Total Posts: 45720
01 Jun 2016 07:21 PM
I gave you an example on how to do that above
Report Abuse
adoman is not online. adoman
Joined: 01 Sep 2010
Total Posts: 306
01 Jun 2016 07:23 PM
okay let me try it real quick..
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image