You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear! I want to fix my script, this script is for a custom drop system that I am making.
-
What is the issue? Include screenshots / videos if possible! Said in title
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub? Yes, no fixes from the dev hub, wiki, or youtube work.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
function Mob:AwardDrops(KilledMob)
local PlayerTags = self.Instance:FindFirstChild("PlayerTags") :: Configuration
if not PlayerTags then return end
for UserId, Damage: number in PlayerTags:GetAttributes() do
UserId = tonumber(UserId)
local Player = Players:GetPlayerByUserId(UserId)
if not Player then continue end
local Percent = Damage / self.Enemy.MaxHealth
if Percent >= 0.25 then
local pData = PlayerData:FindFirstChild(Player.UserId)
local Statistics = pData:FindFirstChild("Stats")
local Items = pData:FindFirstChild("Items")
-- Stats
if Statistics then
for _, StatInfo in self.Config.Drops.Statistics do
local StatName: string = StatInfo[1]
local StatCount: number = StatInfo[2]
local Stat = Statistics:FindFirstChild(StatName)
if Stat then
Stat.Value += StatCount
end
end
end
-- Items
if Items then
for _, ItemInfo in self.Config.Drops.Items do
local ItemType: string = ItemInfo[1]
local ItemName: string = ItemInfo[2]
local DropChance: number = ItemInfo[3]
local Item = ContentLibrary[ItemType] and ContentLibrary[ItemType][ItemName]
if Item then
local isLucky = Random:NextInteger(1, DropChance) == 1
if isLucky then
local droppeditem = game.ReplicatedStorage.ItemDrops:FindFirstChild(ItemType):FindFirstChild(ItemName):Clone()
print(KilledMob.Parent)
workspace.ItemDrops:FindFirstChild(ItemName).CFrame.Position = KilledMob.Parent.Torso.CFrame.Position
droppeditem.Parent = workspace.ItemDrops
ReplicatedStorage.Remotes.SendNotification:FireClient(Player,
"Item Dropped",
self.Config.Name .." dropped ".. Item.Name .." at a 1/".. FormatNumber(DropChance, "Suffix") .." chance.",
Item.Config.IconId
)
end
else
warn("[Kit/MobLib/AwardDrops]: Item doesn't exist: '".. ItemType .."/".. ItemName ..".")
end
end
end
-- TeleportLocation (TP)
local TP = self.Config.TeleportLocation and workspace.TP:FindFirstChild(self.Config.TeleportLocation)
local Character = Player.Character
if TP and Character then
Character:PivotTo(TP.CFrame + Vector3.yAxis*4)
end
end
end
end
CollectionService:GetInstanceAddedSignal("Mob"):Connect(function(MobInstance)
if MobInstance:IsDescendantOf(workspace) then -- For some reason, HD Admin saves a copy of the map under ServerStorage (if you happen to use that), and the MobLib will attempt to clone its copy into workspace.Mobs.
MobLib.new(MobInstance)
end
end)