Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- How to use for i,v loops and what are they?
- -- if i say something wrong pls dm python#9373
- -- for i,v in pairs() is used to loop through a table
- -- If you don't know what tables are have a look at this: https://www.lua.org/pil/2.5.html
- -- Let me show you something:
- for i,v in pairs(game.Workspace:GetDescendants()) do
- print(i.. " - " ..v)
- end
- -- This program loops through the workspace and gets everything
- -- The i stands for index, some people call it key so they do k,v instead of i,v
- -- and the v stands for Value
- -- I print the index concatenated with a dash and the value
- -- So lets say the Baseplate
- -- It could be the 3rd object inside of the workspace since the Terrain and Camera (I think) are first
- -- So while looping, the index will be 3 when at the Baseplate and the value will be the Baseplate
- -- You can do many things with this (exploiters use this alot to their advantage by doing something like below)
- for i,v in pairs(game.Workspace.Coins:GetChildren()) do -- Looping through a possible folder in the game called coins
- if v:IsA("BasePart") and v.Name == "Coin" then -- If the object is a part and its name is 'Coin'
- v.CFrame = game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame -- They will make it teleport to them
- end -- The end of the 'if statement'
- end -- The end of the loop thing
- -- But this is also super helpful for game developers
- for i,v in pairs(game.Workspace.Lava:GetChildren()) do -- Looping through a folder in the workspace called 'Lava'
- if v:IsA("BasePart") and v.Name == "Lava" then -- If the object is a part and its name is 'Lava'
- v.Touched:Connect(function(object) -- Then when it's touched
- if object.Parent:FindFirstChild("Humanoid") then -- If the object that touched it has a humanoid
- object.Parent.Humanoid.Health = 0 -- We will set the health to 0, killing them
- end -- end of 'if statement'
- end) -- end of function (.Touched event)
- end -- end of 'if' statement
- end -- end of for i,v loop thing
- --[[
- If this was hard to follow, I understand; my explaining was kinda bad (really bad)
- Dm me at python#9373 if u want more info
- --]]
- -- Also you can loop through almost anything, not just workspace objects or workspace
- -- quick example:
- for i,v in pairs(game.Lighting:GetDescendants()) do -- Looping through Lighting
- if v.Name == "Beams" and game.Players.LocalPlayer.Graphics.Value == "Low" then
- v:Destroy()
- end
- end
Add Comment
Please, Sign In to add comment