KlovodJoin Date: 2012-07-10 Post Count: 4157 |
My script will look in the player for a model and then look inside the model for a head.
Basically like this. Workspace.Player.Model.Head.Transparency = 0
It's simple but the problem is that I need to tell the script to find all heads inside the player and make it fully transparent. If I say findFirstChild("Head"), it doesn't find the head because the head is in the model. What do I do to solve this??
function onTouch(part)
local human = part.Parent:findFirstChild("Humanoid")
if human ~= nil then
part.Parent:findFirstChild("Model").Head.Transparency = 1
end
end
script.Parent.Touched:connect(onTouch)
|
|
|
You mean like:
local model = part.Parent:FindFirstChild('Model')
if model then
local head = mode:FindFirstChild('Head')
if head then
head.Transparency = 1
end
end |
|
KlovodJoin Date: 2012-07-10 Post Count: 4157 |
I know that I can just say "findFirstChild("Model").Head" but I just can't do that because of anoter reason. I need it to just look in the player for all strings called head. |
|
|
local head = model:FindFirstChild('Head') * |
|
KlovodJoin Date: 2012-07-10 Post Count: 4157 |
Thank you^^^ |
|
|
If you are searching for all heads inside the character, which could be stored inside anything else:
local heads = {}
function SearchForHead(par)
for _, v in pairs(par) do
if v:IsA('Part') and par.Name == 'Head' then
table.insert(heads, v)
else
SearchForHead(v)
end
end
end
SearchForHead(Character) -- put a link to the character here |
|
KlovodJoin Date: 2012-07-10 Post Count: 4157 |
Can you put your script in my script for me? I tried doing it and it won't make the head in the model transparent.
It works like this: Player.(local model).Head.Transparency = 0 |
|
KlovodJoin Date: 2012-07-10 Post Count: 4157 |
I have a name command script that makes your head transparent and then creates a model in the player and in the model is a head and humanoid. When you say your name, for example "name/ROBLOX," the name of the model will be ROBLOX. I need my script to look in the player for that model and change the transparency of the head in the model to 1.
Remember that the model can have any string. |
|
|
local heads = {}
function SearchForHead(par)
for _, v in pairs(par) do
if v:IsA('Part') and v.Name == 'Head' then
table.insert(heads, v)
else
SearchForHead(v)
end
end
end
script.Parent.Touched:connect(function(part)
local human = part.Parent:findFirstChild("Humanoid")
if human then
SearchForHead(human.Parent)
for _, v in pairs(heads) do
v.Transparency = 1
end
end
end) |
|
|
Oh, there is only one head, ignore that script XD |
|
|
Will just come up with a script, hold on |
|
KlovodJoin Date: 2012-07-10 Post Count: 4157 |
okay, let me explain further.
You know how there is a head inside the player? Ignore that. Let's say there is a model inside the player and it has a head inside that model that is not transparent while the original head is. I want both heads to be transparent. So there are two heads in the player but one of those heads is in a model and that model is in the player.
Player.head (that is already transparent, it doesn't matter. Ignore it)
Player.Model.Head (that head is not transparent and is fully visible, I want to attack that head to make it transparent so then both heads can be transparent together.)
If you attack both heads in the player then it won't make sense because one of those heads is already transparent. The head I want to attack is the head that is in a model. I want it to be transparent when you touch a part |
|
KlovodJoin Date: 2012-07-10 Post Count: 4157 |
This is the script that I comprised with yours, it isn't working.
function onTouch(part)
local human = part.Parent:findFirstChild("Humanoid")
if human ~= nil then
local model = part.Parent:FindFirstChild('Model')
if model then
local head = model:findFirstChild('Head') *
if head then
head.Transparency = 1
end
end
script.Parent.Touched:connect(onTouch)
|
|
|
Think I got it this time:
script.Parent.Touched:connect(function(part)
local human = part.Parent:FindFirstChild('Humanoid')
if human then
local char = human.Parent
local model = nil
for _, v in pairs(char:GetChildren()) do
if v:IsA('Model') then
model = v
break
end
end
if model then
local head = model:FindFirstChild('Head')
if head then
head.Transparency = 1
end
end
end
end) |
|
KlovodJoin Date: 2012-07-10 Post Count: 4157 |
Oh my god, it actually worked. You deserve a cookie. |
|