DenisxdX3
(DenisX3)
January 13, 2022, 4:25pm
#1
I was wondering if there is another way to spawn a object based on a %chance
I am currently using a r = math.random(1,100)
and with a for loop for every spawn point i check if the number is in the range to be spawned
Example
if r > 0 and r <= 20 then -> Spawn Object 1
elseif r > 20 and r <= 40 then -> Spawn Object 2
and so on for them all
NOTE: Since this is a spawn point i only want one object to spawn
1 Like
rtvr56565
(rtvr56565)
January 13, 2022, 4:28pm
#2
Uhm… like this?
game.Players.ayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function()
local c = math.random(1,2)
if c == 1 then
plr.Character.HumanoidRootPart.CFrame = workspace.Spawn1.CFrame
elseif c== 2 then
--etc...
end)
end)
DenisxdX3
(DenisX3)
January 13, 2022, 4:30pm
#3
Yes but using the math.random 1,100 i emulate a %chance so
if r > 0 and r <= 20 then -> Spawn Object 1
This will be equal to a 20% chance
if r > 20 and r <= 100 then -> Spawn Object 2
This one will be equal to a 80% chance
The one you posted just spawns them randomly
rtvr56565
(rtvr56565)
January 13, 2022, 4:31pm
#4
Is only do the same but with others chances
if c => 1 and c < 10 then -- only example
Kaid3n22
(Kaiden)
January 13, 2022, 4:44pm
#5
While I don’t think theres any other way, you can shorten it by doing this:
if r <= 20 then
elseif r <= 40 then
as the second elseif will only run if the first is false.
1 Like