|
| 08 May 2017 06:16 PM |
| So I need help with a random tool giver script, so when you spawn it grabs any weapons from server storage or etc, and puts it into your backpack. |
|
|
| Report Abuse |
|
|
| |
|
| |
|
| |
|
Exeplex
|
  |
| Joined: 29 May 2008 |
| Total Posts: 1081 |
|
|
| 08 May 2017 06:27 PM |
local Tools = {};
for i,t in pairs(Location:GetChildren()) do if (t:IsA("Tool")) then -- Check if it's a tool table.insert(Tools, t); -- Add it in the table! end end
local Tool = Tools[math.random(1, #Tools)]; -- Pick a random one out of the table! |
|
|
| Report Abuse |
|
|
Exeplex
|
  |
| Joined: 29 May 2008 |
| Total Posts: 1081 |
|
|
| 08 May 2017 06:31 PM |
| Of course, change the "Location" part. Or, even better, make it a variable in case you ever change the location! |
|
|
| Report Abuse |
|
|
|
| 08 May 2017 07:18 PM |
Here is the script. Anything wrong with it?
local Earth = game.Lighting.Earth local Fire = game.Lighting.Fire while true do wait(1) Magic = math.random(1.2) if Magic == 1 then Earth:Clone() Earth.Parent = game.Players.Backpack if Magic == 2 then Fire:Clone() Fire.Parent = game.Workspace.Players.Backpack end end end |
|
|
| Report Abuse |
|
|
|
| 08 May 2017 07:19 PM |
u dont understand how if statements work
a number cant be 1 and 2 at the same time (it doesnt change) |
|
|
| Report Abuse |
|
|
Exeplex
|
  |
| Joined: 29 May 2008 |
| Total Posts: 1081 |
|
|
| 08 May 2017 07:50 PM |
math.random() works by putting a minimum and maximum value. Example: math.random(3, 9);
It will pick randomly from 3 to 9.
--
Create a GameTools Folder in lighting and place your Earth and Fire inside of it. (You can re-name it later)
local Tools = {};
for i,t in pairs(GameTools:GetChildren()) do if (t:IsA("Tool")) then -- Check if it's a tool table.insert(Tools, t); -- Add it in the table! end end
local Tool = Tools[math.random(1, #Tools)]; -- Pick a random one out of the table! |
|
|
| Report Abuse |
|
|
|
| 08 May 2017 08:26 PM |
| sorry for giving you guys all this trouble. I am only a beginner at scripting |
|
|
| Report Abuse |
|
|