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 » Scripting Helpers
Home Search
 

Re: Am I calling this correctly?

Previous Thread :: Next Thread 
devBq is not online. devBq
Joined: 17 Dec 2013
Total Posts: 154
23 Dec 2013 10:37 PM
local Colours = EquipmentFrame.H:GetChildren()
function ChooseColorHead()
for i=1,#Colours do
if Colours[i].Name == "Color" then
Player.Character.Head.BrickColor = Color3.new(Colours[i].BackgroundColor3)
end
end
end
Colours[i].MouseButton1Click:connect(ChooseColorHead)
Report Abuse
wazap is not online. wazap
Joined: 29 Jun 2007
Total Posts: 23234
23 Dec 2013 10:39 PM
If this is the entire script, then no, because so many things are not defined.

btw
Player.Character.Head.BrickColor = Colours[i].BackgroundColor
Report Abuse
devBq is not online. devBq
Joined: 17 Dec 2013
Total Posts: 154
23 Dec 2013 10:42 PM
This isn't the entire script.

Would this be right?

local Colours = EquipmentFrame.H:GetChildren()
function ChooseColorHead()
for i=1,#Colours do
if Colours[i].Name == "Color" then
Player.Character.Head.BrickColor = Colours[i].BackgroundColor
end
end
Colours[i].MouseButton1Click:connect(ChooseColorHead)
end
Report Abuse
wazap is not online. wazap
Joined: 29 Jun 2007
Total Posts: 23234
23 Dec 2013 10:46 PM
I think you want this

local Colours = EquipmentFrame.H:GetChildren()

function ChooseColorHead(button)
Player.Character.Head.BrickColor = button.BackgroundColor
end

for i = 1, #Colours do
if Colours[i].Name == "Color" then
Colours[i].MouseButton1Click:connect(function() ChooseColorHead(Colours[i]) end)
Report Abuse
wazap is not online. wazap
Joined: 29 Jun 2007
Total Posts: 23234
23 Dec 2013 10:46 PM
... add 2 ends to the end of the script I posted...
Report Abuse
devBq is not online. devBq
Joined: 17 Dec 2013
Total Posts: 154
23 Dec 2013 10:48 PM
Wow!
You are a life saver.
Thank you very much!
Report Abuse
devBq is not online. devBq
Joined: 17 Dec 2013
Total Posts: 154
23 Dec 2013 10:51 PM
What if I wanted to repeat it.
'Cause I want to do this for torso, arms, leg etc..
IS there a more efficent way?

--HEAD

local Colours = EquipmentFrame.H:GetChildren()
function ChooseColorHead(button)
Player.Character.Head.BrickColor = button.BackgroundColor
end

for i = 1, #Colours do
if Colours[i].Name == "Color" then
Colours[i].MouseButton1Click:connect(function() ChooseColorHead(Colours[i]) end)
end
end


--TORSO

local ColoursB = EquipmentFrame.T:GetChildren()
function ChooseColorTorso(button)
Player.Character.Head.BrickColor = button.BackgroundColor
end

for i = 1, #ColoursB do
if ColoursB[i].Name == "Color" then
ColoursB[i].MouseButton1Click:connect(function() ChooseColorTorso(ColoursB[i]) end)
end
end
Report Abuse
wazap is not online. wazap
Joined: 29 Jun 2007
Total Posts: 23234
23 Dec 2013 11:01 PM
Do you want 1 button to color the entire player? Or seperate colors for each body part?
Report Abuse
devBq is not online. devBq
Joined: 17 Dec 2013
Total Posts: 154
23 Dec 2013 11:04 PM
Seperate here's an exmaple

local Colours = EquipmentFrame.H:GetChildren()
function ChooseColorHead(button)
Player.Character.Head.BrickColor = button.BackgroundColor
end
for i = 1, #Colours do
if Colours[i].Name == "Color" then
Colours[i].MouseButton1Click:connect(function() ChooseColorHead(Colours[i]) end)
end
end

local ColoursB = EquipmentFrame.T:GetChildren()
function ChooseColorTorso(button)
Player.Character.Torso.BrickColor = button.BackgroundColor
end
for i = 1, #ColoursB do
if ColoursB[i].Name == "Color" then
ColoursB[i].MouseButton1Click:connect(function() ChooseColorTorso(ColoursB[i]) end)
end
end

local ColoursC = EquipmentFrame.LL:GetChildren()
function ChooseColorLeftLeg(button)
Player.Character:FindFirstChild("Left Leg").BrickColor = button.BackgroundColor
end
for i = 1, #ColoursC do
if ColoursC[i].Name == "Color" then
ColoursC[i].MouseButton1Click:connect(function() ChooseColorLeftLeg(ColoursC[i]) end)
end
end

local ColoursD = EquipmentFrame.RL:GetChildren()
function ChooseColorRightLeg(button)
Player.Character.Torso.BrickColor = button.BackgroundColor
end
for i = 1, #ColoursD do
if ColoursD[i].Name == "Color" then
ColoursD[i].MouseButton1Click:connect(function() ChooseColorRightLeg(ColoursD[i]) end)
end
end

local ColoursE = EquipmentFrame.T:GetChildren()
function ChooseColorRightLeg(button)
Player.Character.Head.BrickColor = button.BackgroundColor
end
for i = 1, #ColoursE do
if ColoursE[i].Name == "Color" then
ColoursE[i].MouseButton1Click:connect(function() ChooseColorTorso(ColoursE[i]) end)
end
end
Report Abuse
wazap is not online. wazap
Joined: 29 Jun 2007
Total Posts: 23234
23 Dec 2013 11:15 PM
local bodyPart = ""
for p, i in pairs(EquipmentFrame:GetChildren()) do
i.MouseButton1Click:connect(function() bodyPart = i.Name
for q, r in pairs(i:GetChildren()) do
if r.Name == "Color" then
r.MouseButton1Click:connect(function() Player.Character[i.Name].BrickColor = r.BackgroundColor end) end end end)
end

The change requires you to name everything in EquipmentFrame to the name of the corresponding bodypart... i.e LL into Left Leg H into Head, and so on.
Report Abuse
devBq is not online. devBq
Joined: 17 Dec 2013
Total Posts: 154
23 Dec 2013 11:26 PM
MouseButton1Click is not a valid member of Frame

i.MouseButton1Click:connect(function() bodyPart = i.Name
Report Abuse
wazap is not online. wazap
Joined: 29 Jun 2007
Total Posts: 23234
23 Dec 2013 11:32 PM
o.e
Turn the body part frame into either TextButtons or ImageButtons...


and throw in if i:IsA("Frame") then i.MouseButton1Click:connect... blah blah...
idk thats the most efficient way to do it... otherwise
plz
use
the
other
inefficient
method
:x
Report Abuse
wazap is not online. wazap
Joined: 29 Jun 2007
Total Posts: 23234
23 Dec 2013 11:32 PM
I'm stupid.. I mean if i:IsA("TextButton") or i:IsA("ImageButton") then
Report Abuse
devBq is not online. devBq
Joined: 17 Dec 2013
Total Posts: 154
23 Dec 2013 11:40 PM
Well it's working now.

local bodyPart = ""
for p, i in pairs(EquipmentFrame:GetChildren()) do
if i:IsA("TextButton") or i:IsA("ImageButton") then
i.MouseButton1Click:connect(function() bodyPart = i.Name
for q, r in pairs(i:GetChildren()) do
if r.Name == "Color" then
r.MouseButton1Click:connect(function() Player.Character[i.Name].BrickColor = r.BackgroundColor end) end end end)
end
end

But every time I click the button to change the character's color, it doens't change. Not sure what's wrong.
Report Abuse
devBq is not online. devBq
Joined: 17 Dec 2013
Total Posts: 154
24 Dec 2013 11:33 AM
vump
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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