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

Random math doesn't work randomly ?

Asked by 3 years ago

I am trying to make a part that has a 50% chance of spawning a wood on it's position, but when I copy more of the blocks and start the game it just spawns on all of them or on none, no erros, and I have no idea how would I fix it

The block is just a half transparent part with a single script in it, the wood is in replicatedstorage

math.randomseed(tick())

local random = math.random(1,400)

if random > 1 and random < 200 then
    local wud = game.ReplicatedStorage.Wood:Clone()
    wud.Parent = game.Workspace
    wud:MoveTo(script.Parent.Position)

elseif random > 200 and random < 400 then
    print("nothing")


end

script.Parent:Destroy()
0
i think u should put a space after math.randomseed and math.random beastboykafan -5 — 3y
0
Like this ? "math.random (1,400)" instead of this ? "math.random(1,400)" kikocraftak233 18 — 3y
0
If yes that didn't make any difference kikocraftak233 18 — 3y
0
Correct me if im wrong but math.random(1,2) is a 50/50 chance.. you have 50% chance to get either 1 or 2 so why wont you just do that instead? If its 1 then spawn a wood and if its not 1 you dont even need to specify anything else.. it doesnt know what to do when its 2 so it wont do anything so no need for that print("nothing") HeyItzDanniee 252 — 3y
View all comments (2 more)
0
Okay, I will try that kikocraftak233 18 — 3y
0
Nope, still does the same, I copy and paste the parts like 20 of them, once they all spawn wood and once nothing kikocraftak233 18 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

You dont nescesarily need to add :MoveTo you could just change the position via Explorer or just change it in the script. I used Instance.new() to show you the point. Also If you are doing a 50% chance, you should use a range of 1,2

Here is an example

local random = math.random(1,2)
local debounce = false
bool = true

while bool == true do
    print(random)
    if random == 1 and debounce == false then
        local wud = Instance.new('Part')
        wud.Transparency = .5
        wud.Position = Vector3.new(-88.89, 0.5, 36.11) -- Change Pos
        wud.BrickColor = BrickColor.new('Brown')
        wud.Parent = game.Workspace
        debounce = true
        wait(2)
        debounce = false
    elseif random == 2 and debounce == false then
        print("nothing")
        debounce = true
        wait(2)
        debounce = false
    end
end


Some Error Reasons -

  • The reason why it spawns all at once is because you have no debounce or wait time as it is a infinite loop,
Ad

Answer this question