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

How do I make it so this script gives a random amount of gold after the Player kills the mob?

Asked by
flanfy -3
5 years ago

I want it so when a player kills this mob, the mob will drop random amount of gold between the min and max value of gold that can be dropped from that mob. Here is the script.

local _M = require(script.Parent.MobConfig)
local Mob = script.Parent
local Enemy = Mob.Enemy

function Award()
    if (Mob == nil) or (Enemy == nil) then return end
    if (not Enemy:FindFirstChild("Player_Tag")) then return end
    local Tag = Enemy:FindFirstChild("Player_Tag")
    if (not Tag) and (not Tag.Value) then return end
    local plr = Tag.Value
    if (not plr:FindFirstChild("leaderstats")) then return end
    local stats = plr:FindFirstChild("leaderstats")
    if (not stats:FindFirstChild("XP")) then return end
    if (not stats:FindFirstChild("Gold")) then return end
    wait(0.1)
    if script.FinalHitTrue.Value == true then
        stats.XP.Value = stats.XP.Value + _M.AwardedXP
        stats.Gold.Value = stats.Gold.Value + _M.AwardedGold
    end
end

Enemy.Died:Connect(Award)

1 answer

Log in to vote
0
Answered by 5 years ago

math.random is the easiest way to put it.

so do

math.random(minamount, maxamount)
Ad

Answer this question