So, basically, I made this script, where when you step on this part, a random body part of yours catches fire. Here's the script:
01 | local part = script.Parent |
02 | local db = false |
03 |
04 | function burn(hit) |
05 |
06 | local p 1 = hit.Parent:FindFirstChild( "Left Arm" ) |
07 | local p 2 = hit.Parent:FindFirstChild( "Right Arm" ) |
08 | local p 3 = hit.Parent:FindFirstChild( "Left Leg" ) |
09 | local p 4 = hit.Parent:FindFirstChild( "Right Leg" ) |
10 | local p 5 = hit.Parent:FindFirstChild( "Torso" ) |
11 | local fire = Instance.new( "Fire" ) |
12 | local human = hit.Parent:FindFirstChild( "Humanoid" ) |
13 | local myArray = { p 1 , p 2 , p 3 , p 4 , p 5 } |
14 |
15 | if human then |
It's supposed to take one of the bodyparts in "myArray", but it doesn't and says I gave it a bad argument. Any ideas? All help is appreciated!
Your first problem is that you used math.random()
improperly. It requires a start and end point from which it can select a random value. What you did was not feed it a number, but feed it an object, which it won't be able to understand. The generic for is also completely unnecessary, when rather than running through all of the values, you could've just ran math.random()
once and indexed the value it returned.
Your code:
01 | local part = script.Parent |
02 | local db = false |
03 |
04 | function burn(hit) |
05 |
06 | local p 1 = hit.Parent:FindFirstChild( "Left Arm" ) |
07 | local p 2 = hit.Parent:FindFirstChild( "Right Arm" ) |
08 | local p 3 = hit.Parent:FindFirstChild( "Left Leg" ) |
09 | local p 4 = hit.Parent:FindFirstChild( "Right Leg" ) |
10 | local p 5 = hit.Parent:FindFirstChild( "Torso" ) |
11 | local fire = Instance.new( "Fire" ) |
12 | local human = hit.Parent:FindFirstChild( "Humanoid" ) |
13 | local myArray = { p 1 , p 2 , p 3 , p 4 , p 5 } |
14 |
15 | if human then |
Your code with changes:
01 | local part = script.Parent |
02 | local db = false |
03 |
04 | function burn(hit) |
05 |
06 | local p 1 = hit.Parent:FindFirstChild( "Left Arm" ) |
07 | local p 2 = hit.Parent:FindFirstChild( "Right Arm" ) |
08 | local p 3 = hit.Parent:FindFirstChild( "Left Leg" ) |
09 | local p 4 = hit.Parent:FindFirstChild( "Right Leg" ) |
10 | local p 5 = hit.Parent:FindFirstChild( "Torso" ) |
11 | local fire = Instance.new( "Fire" ) |
12 | local human = hit.Parent:FindFirstChild( "Humanoid" ) |
13 | local myArray = { p 1 , p 2 , p 3 , p 4 , p 5 } |
14 |
15 | if human then |
If this helped you, please don't forget to upvote and accept the answer :)
You don't need to loop through the table. Just place the fire on a random object in the table. To get something randomly out of a table, you would index a random value within the index of the table.
01 | local part = script.Parent |
02 | local db = false |
03 |
04 | function burn(hit) |
05 | local human = hit.Parent:FindFirstChild( "Humanoid" ) |
06 |
07 | if human then |
08 | local p 1 = hit.Parent:FindFirstChild( "Left Arm" ) |
09 | local p 2 = hit.Parent:FindFirstChild( "Right Arm" ) |
10 | local p 3 = hit.Parent:FindFirstChild( "Left Leg" ) |
11 | local p 4 = hit.Parent:FindFirstChild( "Right Leg" ) |
12 | local p 5 = hit.Parent:FindFirstChild( "Torso" ) |
13 | local fire = Instance.new( "Fire" ) |
14 | local myArray = { p 1 , p 2 , p 3 , p 4 , p 5 } |
15 |
That's the answer for how I understood your question. If this isn't what you wanted, please tell me exactly what you want in the comments below.
Good Luck!