Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Help with script, for loops?

Asked by 8 years ago

I'm making a script for my upcoming game Papa John's 2. And the idea is to have an algorithm determine if you are papa bless and this problem is persistent thru the entire loop and idk why?

local blessrange = 100
local leader = 'ScriptGuider'
local secretsauce = math.random(1,blessrange)

function papabless(player)
     if player:IsA('Object') then
           print(player.Name..(' Has Been Blessed By Papa John's
     end
End

function makeapizza(secretsauce)
     for i,v in pairs(game.Workspace:GetChildren()) do
          if i <= blessrange and i > secretsauce then
               print('A click of the mouse and papas in the house's)
               if game.Players:FindFirstChild(v.Name) ~= nil then
                    v.Humanoid.Health = secretsauce/blessrange
                   if secretsauce/blessrange >= 69 then
                       papabless(v)
                   end
               end
          end
      end
end

makeapizza(secretsauce)

1 answer

Log in to vote
0
Answered by
Validark 1580 Snack Break Moderation Voter
8 years ago

Your issue is on the following line (13):

if i <= blessrange and i > secretsauce then

In the above if statement:

i is the index of an object within the table returned by game.Workspace:GetChildren()

blessrange is 100

secretsauceis a number between 1 and 100 (see line 3)

The only way for the script to run lines 14-20 is if the random number generated is 100, and it is iterating over the 100th object in the GetChildren() table

Also, make sure:

endshould always be lower case

quotes should always be formatted correctly (if the highlighting is inconsistent, you made a mistake in syntax)

Another thing, on line 6, you have

if player:IsA('Object') then

There is no Object class that objects can inherit from. Please see Roblox wiki for where objects inherit properties and functions from.

For example, a Frame inherits from GuiObject, GuiBase2d, GuiBase, and Instance

Ad

Answer this question