Random potion effect

Hey developers, Today I made a potion that has 2 effects Heal and walkspeed I want to make it so it picks one random effect but I don’t know how to make it random
here’s the script:

local Debounce = false

local tool = script.Parent

tool.Activated:Connect(function()
if not Debounce then
Debounce = true
local humanoid = tool.Parent:FindFirstChild(“Humanoid”)
humanoid.Health = humanoid.Health + 10
humanoid.WalkSpeed = humanoid.WalkSpeed + 9
task.wait(1)

	Debounce = false
end

end)
Thanks.

You could use math.random

Lets say you have 2 numbers,1 and 2.

And if the number was 1 → heal.
If the number was 2 → give walkspeed.

Example:

local num = math.random(1,2)

if num == 1 then
--heal
elseif num == 2 then
--give speed
end

In your case:



local Debounce = false

local tool = script.Parent

tool.Activated:Connect(function()
if not Debounce then
Debounce = true
local humanoid = tool.Parent:FindFirstChild(“Humanoid”)

local Num = math.random(1,2)
    if Num ==  1 then
       humanoid.Health +=  10
    elseif Num ==  2 then
        humanoid.WalkSpeed += 9
    end
     task.wait(1)
     Debounce = false
    end
end)

An alternative way would be to store them in a table and choose a random one out of that table.

1 Like

Just choose them from a list, Example:

local powers = {“WS”, “H”}

local power = powers[math.random(1,#powers)]