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: Simple Script question

Previous Thread :: Next Thread 
Gnago is not online. Gnago
Joined: 28 Jan 2014
Total Posts: 372
01 May 2015 07:02 PM
I'm learning Lua through getting free scripts off free models and editing them to do something slightly different, and I was wondering if the "i" in this script is just a variable, or if its a concept... Also, if possible I would appreciate if someone could also explain what '#' means, thanks!

function Weld(x,y)
local W = Instance.new("Weld")
W.Part0 = x
W.Part1 = y
local CJ = CFrame.new(x.Position)
local C0 = x.CFrame:inverse()*CJ
local C1 = y.CFrame:inverse()*CJ
W.C0 = C0
W.C1 = C1
W.Parent = x
end

local D = false
function onTouch(hit)
if D == false then
D = true
if hit.Parent:findFirstChild("Humanoid") ~= nil then
if hit.Parent:findFirstChild("Humanoid").Health > 0 then
local P = hit.Parent:GetChildren()
local M = Instance.new("Model") -- This is the Clone
local H = Instance.new("Humanoid")
M.Parent = game.Workspace
M.Name = hit.Parent.Name
if hit.Parent:findFirstChild("Pants") ~= nil then
hit.Parent.Pants.Parent = M
end
if hit.Parent:findFirstChild("Shirt") ~= nil then
hit.Parent.Shirt.Parent = M
end
for i=1, #P do
if P[i].className == "Part" then
local C = P[i]:clone()
C.Parent = M
C.Locked = false
C.CanCollide = true
P[i]:remove()
end
if P[i].className == "Hat" then
P[i].Parent = M
end
end
M:MoveTo(Vector3.new(198.84, -24.6, -269.57))
M:MakeJoints()
local P = M:GetChildren()
for i=1, #P do
if P[i].Name ~= "Torso" and P[i].Name ~= "Pants" and P[i].Name ~= "Shirt" and P[i].className ~= "Hat" then
Weld(M.Torso,P[i])
end
if P[i].className == "Hat" then
Weld(M.Torso,P[i].Handle)
end
end
H.Parent = M
end
end
wait(2)
D = false
end
end

script.Parent.Touched:connect(onTouch)
Report Abuse
Gnago is not online. Gnago
Joined: 28 Jan 2014
Total Posts: 372
01 May 2015 07:03 PM
BTW this is a cloning script, incase you couldn't find out and needed to know...
Report Abuse
Gnago is not online. Gnago
Joined: 28 Jan 2014
Total Posts: 372
02 May 2015 08:48 AM
Bump
Report Abuse
Intern33t is not online. Intern33t
Joined: 19 Nov 2010
Total Posts: 1530
02 May 2015 08:53 AM
local tab = {342, "potato", math.pi}
local w = #tab

print(w)


Will print

3



because # returns the length of a table.

When he uses P[i], he targets the i'th element (i = 3, 3th element, i= = 2, 2nd element)
of the array P
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