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 » Game Design
Home Search
 

Re: Locating a model with a specific intvalue inside.

Previous Thread :: Next Thread 
Kie413Games is not online. Kie413Games
Joined: 06 May 2010
Total Posts: 3896
18 Dec 2015 04:53 AM
So basically, in replicated storage I have 10 of the same named model "Small Frenium Asteroid". Each one has a IntValue in them called id. What I want it to do is find the Small Frenium Asteroid with for example the id value of 4. How could I do this?

local Self = script.Parent
local NPC = game.ReplicatedStorage.Resources:WaitForChild("Small Frenium Asteroid"):Clone()

Self:WaitForChild("Humanoid").Died:connect(function()
wait(25)
local NewNPC = NPC:Clone()
NewNPC.Parent = Self.Parent
NewNPC:MakeJoints()
Self:Destroy()
end)
Report Abuse
ROBLOXBattleChamp is not online. ROBLOXBattleChamp
Joined: 02 Mar 2010
Total Posts: 176
18 Dec 2015 04:57 AM
local children = game.ReplicatedStorage:GetChildren()

for i = 1,#children do
if children[i].Name == "Small Frenium Asteroid" and children[i].id ~= nil then
if children[i].id == 4 then
--Fire event
end
end
end
Report Abuse
Kie413Games is not online. Kie413Games
Joined: 06 May 2010
Total Posts: 3896
18 Dec 2015 05:11 AM
How would I clone that specific "Small Frenium Asteroid" with the id of 4?
Report Abuse
Kie413Games is not online. Kie413Games
Joined: 06 May 2010
Total Posts: 3896
18 Dec 2015 05:20 AM
I used your script and did this, but it doesn't work.

local Self = script.Parent
local children = game.ReplicatedStorage:GetChildren()

for i = 1, #children do
if children[i].Name == "Small Frenium Asteroid" and children[i].id ~= nil then
if children[i].id == 4 then
Self:WaitForChild("Humanoid").Died:connect(function()
wait(25)
local NewNPC = children:Clone()
NewNPC.Parent = Self.Parent
NewNPC:MakeJoints()
Self:Destroy()
end)
end
end
end
Report Abuse
ROBLOXBattleChamp is not online. ROBLOXBattleChamp
Joined: 02 Mar 2010
Total Posts: 176
18 Dec 2015 05:40 AM
What exactly are you trying to accomplish with that death function?
Also, depending on the expected result, the issue may be that you are trying to clone all of the ReplicatedStorage with "local NewNPC = children:Clone()"


try:
m = Instance.new("Model",game.Workspace) --or ReplicatedStorage, not sure exactly what your goal is here
m.Name = "Small Frenium Asteroid"

local NewNPC = Self:GetChildren()
for x = 1,#NewNPC do
NewNPC[x]:clone().Parent = m
NewNPC:MakeJoints()
end
Self:Destroy()
Report Abuse
Kie413Games is not online. Kie413Games
Joined: 06 May 2010
Total Posts: 3896
18 Dec 2015 05:43 AM
I thought the death function would be better than a while true do / while wait() do to constantly check if the humanoid.health < 1.

Report Abuse
ROBLOXBattleChamp is not online. ROBLOXBattleChamp
Joined: 02 Mar 2010
Total Posts: 176
18 Dec 2015 05:57 AM
I understand why waiting for the death event to be fired, what I dont understand is what you want to happen after that happens. Are you trying to make the NPC regenerate infinitesimally after it dies?
Report Abuse
Kie413Games is not online. Kie413Games
Joined: 06 May 2010
Total Posts: 3896
18 Dec 2015 06:01 AM
What I wanted to do is, on a map have like about 10 of let's say, Small Frenium Asteroids each with the same name, but a IntValue inside each one with a different value between 1 and 10. Then let's say the Small Frenium Asteroid with the id 7 gets killed. It will look inside ReplicatedStorage, find the correct Small Frenium Asteroid with the id of 7. And then it puts that into the group of NPCs and removes the destroyed one.
Report Abuse
chimmihc is not online. chimmihc
Joined: 01 Sep 2014
Total Posts: 17143
18 Dec 2015 06:06 AM
local RPS = game:GetService("ReplicatedStorage")
local Resources = RPS:WaitForChild("Resources")

local function GetObjFromId(name,id)
for i,v in next, Resources:GetChildren() do
if v.Name == name then
local id = v:FindFirstChild("id")
if id then
if id.Value == id then
return v
end
end
end
end
return nil
end

local Object = GetObjFromId("Small Frenium Asteroid",4)

script.Parent:WaitForChild("Humanoid").Died:connect(function()
wait(25)
local NewNPC = Object:Clone()
NewNPC.Parent = script.Parent.Parent
NewNPC:MakeJoints()
script.Parent:Destroy()
end)
Report Abuse
Kie413Games is not online. Kie413Games
Joined: 06 May 2010
Total Posts: 3896
18 Dec 2015 06:11 AM
chimmihc, I get this in the output:

12:10:56.067 - Workspace.Frenium_Asteroids.Resources.Small Frenium Asteroid.Resource_Respawn:22: attempt to index upvalue 'Object' (a nil value)
12:10:56.068 - Stack Begin
12:10:56.069 - Script 'Workspace.Frenium_Asteroids.Resources.Small Frenium Asteroid.Resource_Respawn', Line 22
12:10:56.069 - Stack End
Report Abuse
chimmihc is not online. chimmihc
Joined: 01 Sep 2014
Total Posts: 17143
18 Dec 2015 06:18 AM
local RPS = game:GetService("ReplicatedStorage")
local Resources = RPS:WaitForChild("Resources")

local function GetObjFromId(name,id)
for i,v in next, Resources:GetChildren() do
if v.Name == name then
local id = v:FindFirstChild("id")
if id then
if id.Value == id then
return v
end
end
end
end
return nil
end

script.Parent:WaitForChild("Humanoid").Died:connect(function()
wait(25)
local Object = GetObjFromId("Small Frenium Asteroid",4)
if Object then
local NewNPC = Object:Clone()
NewNPC.Parent = script.Parent.Parent
NewNPC:MakeJoints()
script.Parent:Destroy()
else
print("No object found")
script.Parent:Destroy()
end
end)
Report Abuse
Kie413Games is not online. Kie413Games
Joined: 06 May 2010
Total Posts: 3896
18 Dec 2015 06:31 AM
Comes up with "No object found", but the Small Frenium Asteroid has an id inside of it with the value 4. huh?
Report Abuse
chimmihc is not online. chimmihc
Joined: 01 Sep 2014
Total Posts: 17143
18 Dec 2015 06:35 AM
Try this debug code and post what outputs.

local RPS = game:GetService("ReplicatedStorage")
local Resources = RPS:WaitForChild("Resources")

local function GetObjFromId(name,id)
for i,v in next, Resources:GetChildren() do
if v.Name == name then
local id = v:FindFirstChild("id")
if id then
if id.Value == id then
return v
else
print("Object has wrong id")
end
else
print("Object has no id")
end
else
print("Object has wrong name")
end
end
return nil
end

script.Parent:WaitForChild("Humanoid").Died:connect(function()
wait(25)
local Object = GetObjFromId("Small Frenium Asteroid",4)
if Object then
local NewNPC = Object:Clone()
NewNPC.Parent = script.Parent.Parent
NewNPC:MakeJoints()
script.Parent:Destroy()
else
print("No object found")
script.Parent:Destroy()
end
end)
Report Abuse
Kie413Games is not online. Kie413Games
Joined: 06 May 2010
Total Posts: 3896
18 Dec 2015 06:38 AM
Object has wrong id
Object has wrong id
Object has wrong id
No object found
Report Abuse
Kie413Games is not online. Kie413Games
Joined: 06 May 2010
Total Posts: 3896
18 Dec 2015 06:41 AM
Also, I put three in replicatedstorage.Resources just to see if it was able to find the correct 1. 1 of them does have the id of 4 though
Report Abuse
chimmihc is not online. chimmihc
Joined: 01 Sep 2014
Total Posts: 17143
18 Dec 2015 06:45 AM
XD

local RPS = game:GetService("ReplicatedStorage")
local Resources = RPS:WaitForChild("Resources")

local function GetObjFromId(name,id)
for i,v in next, Resources:GetChildren() do
if v.Name == name then
local Id = v:FindFirstChild("id")
if Id then
if Id.Value == id then
return v
end
end
end
end
return nil
end

script.Parent:WaitForChild("Humanoid").Died:connect(function()
wait(25)
local Object = GetObjFromId("Small Frenium Asteroid",4)
if Object then
local NewNPC = Object:Clone()
NewNPC.Parent = script.Parent.Parent
NewNPC:MakeJoints()
script.Parent:Destroy()
else
print("No object found")
script.Parent:Destroy()
end
end)
Report Abuse
Kie413Games is not online. Kie413Games
Joined: 06 May 2010
Total Posts: 3896
18 Dec 2015 06:54 AM
Thanks so much, it works very well.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Game Design
   
 
   
  • 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