Im Testing Out math.Random() and I cant seem to do any thing :/ Please Help?
local players = game.Players:GetPlayers() zombie = math.random(1, #players) arm = zombie:FindFirstChild("Left Arm") arm:Remove()
Your code is close to right.
There are two problems:
zombie
would be a Player. Those are the things sitting in the Players service and have things like TeamColor and BackPack. The physical Parts like the arms are in the corresponding Character.We would fix this by doing something like
zombie = zombie.Character
math.random
returns a number. A number isn't a Player. Since we have a list of players
, and each thing in a list has a corresponding number (1
st, 2
nd, 3
rd...) we use this number with players
:zombie = players[ math.random(1, #players) ]
If you're unfamiliar with how tables work, we ask for the n
th thing in a list by using tab[n]
. E.g., list[1]
is the first thing in a list and list[#list]
is the last (in a list of 5
things, the 5
th element is the last one)
So these two fixes together will make this work.
As RoboFrog suggested, though, if this is just the contents of a script in a place you publish, it won't do anything, since it will run before any players join. If this is the contents of an event or part of a larger script, this will work fine (as long as there is at least one player)
How is the script being called upon? Without a function of some sort, this code is useless to the computer.