generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: How would you...

Previous Thread :: Next Thread 
anth4321 is not online. anth4321
Joined: 22 Sep 2009
Total Posts: 29
01 Mar 2014 07:29 PM
do a chance system like on murder mystery or darkness 2
Report Abuse
wazap is not online. wazap
Joined: 29 Jun 2007
Total Posts: 23234
01 Mar 2014 07:31 PM
math.random
Report Abuse
anth4321 is not online. anth4321
Joined: 22 Sep 2009
Total Posts: 29
01 Mar 2014 07:32 PM
no because some players have more chances than others
Report Abuse
wazap is not online. wazap
Joined: 29 Jun 2007
Total Posts: 23234
01 Mar 2014 07:34 PM
still math.random
probs something like this

local table = {}
for i, v in pairs(game.Players:GetPlayers()) do
local percentage = v.Percentage.Value
for i = 1, percentage do
table.insert(table, v)
end
end


Then math.random.
Report Abuse
anth4321 is not online. anth4321
Joined: 22 Sep 2009
Total Posts: 29
01 Mar 2014 07:35 PM
okay I will try that
Report Abuse
anth4321 is not online. anth4321
Joined: 22 Sep 2009
Total Posts: 29
01 Mar 2014 07:40 PM
I think it works but how would you do a math.random on a table?
Report Abuse
wazap is not online. wazap
Joined: 29 Jun 2007
Total Posts: 23234
01 Mar 2014 07:41 PM
srsly
table[math.random#table] leftoutafew()butidrc
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
01 Mar 2014 07:44 PM
wazap, take it easy on him, he's having trouble. I saw his other post, he isn't bad, but sometimes some of us don't learn basic stuff in the beginning, (example; I still haven't learnt IsA() yet)
Report Abuse
MarioKartAddict is not online. MarioKartAddict
Joined: 11 Nov 2009
Total Posts: 42774
01 Mar 2014 07:47 PM
@war
if part:IsA("ClassName") then

basically, it is a conditional used to see if the part in question literally is a Part, or BasePart, or whatever
Report Abuse
anth4321 is not online. anth4321
Joined: 22 Sep 2009
Total Posts: 29
01 Mar 2014 07:47 PM
tryed this: a = math.random(1,#listtable)
but a is a number.
how would I make it the players name?
Report Abuse
anth4321 is not online. anth4321
Joined: 22 Sep 2009
Total Posts: 29
01 Mar 2014 07:48 PM
And thanks for all your help!
Report Abuse
wazap is not online. wazap
Joined: 29 Jun 2007
Total Posts: 23234
01 Mar 2014 07:48 PM
local plr=listtable[a]
Report Abuse
MarioKartAddict is not online. MarioKartAddict
Joined: 11 Nov 2009
Total Posts: 42774
01 Mar 2014 07:49 PM
i got it
if a person had a 3% chance
insert their name 3 times
because % is out of 100
then use math.random on the table to get the random 1%
people with higher percentages have a better chance of getting chosen
Report Abuse
anth4321 is not online. anth4321
Joined: 22 Sep 2009
Total Posts: 29
01 Mar 2014 07:50 PM
It works thanks so much!
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
01 Mar 2014 08:01 PM
@mario so this;

Super5737; 3% (3 times)
Dienowplz; 87% (87 times)
FreakyCreeps; 10% (10 times)
Creepynutso; 0% (0 times)


That works out perfect, but I'd just sooner add their name in 1 time for every round they aren't picked, and revert to 1 when they are, why bother with a percent system?!?
Report Abuse
anth4321 is not online. anth4321
Joined: 22 Sep 2009
Total Posts: 29
01 Mar 2014 09:10 PM
okay I thought it worked until I tryed it in f7 mode with 7 players.
here is my current script:

Vip = {"shadownetwork","anth4321"}
z = 1

listtable = {}
for i, v in pairs(game.Players:GetPlayers()) do
percentage = v.Chance.Value
for i = 1, percentage do
table.insert(listtable, v)
end
end

print(listtable)

function PickAssassin()
a = math.random(1,#listtable)
plr=listtable[a]
if plr.Picked == false then
plr.Assassin = true
plr.Picked = true
print(plr" is assassin")
else
PickAssassin()
end
end

function PickPolice()
a = math.random(1,#listtable)
plr=listtable[a]
if plr.Picked == false then
if z == 1 then
z = 0
plr.SpecialPolice = true
plr.Picked = true
else
plr.Police = true
plr.Picked = true
end
print(plr" is police")
else
PickPolice()
end
end

function PickTarget()
a = math.random(1,#listtable)
plr=listtable[a]
if plr.Picked == false then
plr.Target = true
plr.Picked = true
print(plr" is target")
else
PickTarget()
end
end

function pickplayers()
PickAssassin()
d = math.random(2,4)
for i=1,d do
PickPolice()
end
d = math.random(1,2)
for i=1,d do
PickTarget()
end
end

pickplayers()

Output
22:07:20.161 - Workspace.Script:15: stack overflow
22:07:20.162 - Script 'Workspace.Script', Line 15 - global PickAssassin
22:07:20.164 - Script 'Workspace.Script', Line 22 - global PickAssassin
22:07:20.166 - Script 'Workspace.Script', Line 22 - global PickAssassin
22:07:20.167 - Script 'Workspace.Script', Line 22 - global PickAssassin
22:07:20.169 - Script 'Workspace.Script', Line 22 - global PickAssassin
22:07:20.170 - Script 'Workspace.Script', Line 22 - global PickAssassin
22:07:20.170 - Script 'Workspace.Script', Line 22 - global PickAssassin
22:07:20.171 - Script 'Workspace.Script', Line 22 - global PickAssassin
22:07:20.172 - Script 'Workspace.Script', Line 22 - global PickAssassin
22:07:20.173 - Script 'Workspace.Script', Line 22 - global PickAssassin
22:07:20.174 - Script 'Workspace.Script', Line 22 - global PickAssassin
22:07:20.175 - Script 'Workspace.Script', Line 22 - global PickAssassin
Report Abuse
anth4321 is not online. anth4321
Joined: 22 Sep 2009
Total Posts: 29
01 Mar 2014 09:26 PM
bump
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
02 Mar 2014 05:08 AM
You tried to set off the function INSIDE itself, if you finish declaring it (put proper amount of ends) it should work
Report Abuse
anth4321 is not online. anth4321
Joined: 22 Sep 2009
Total Posts: 29
03 Mar 2014 01:09 PM
I think I fixed it.
going to test it now.
Report Abuse
anth4321 is not online. anth4321
Joined: 22 Sep 2009
Total Posts: 29
03 Mar 2014 01:55 PM
it works thank you all:)
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image