Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

math.random is the easiest way to put it.

so do

math.random(minamount, maxamount)

This discussion is preserved as it was. New answers, comments, and votes are closed.