So i have an script that spawns animals and when you kill them you get loot but for somereason it dosen't work cause it's not being called so how would i do that?
Heres the module script:
local RepStorage = game:GetService("ReplicatedStorage")
local SerStorage = game:GetService("ServerStorage")
local Players = game:GetService("Players")
local EnemyLib = require(RepStorage:WaitForChild("EnemyLibrary").MainModule)
local ItemLib = require(RepStorage:WaitForChild("ItemLibrary").MainModule)
local remote = RepStorage:WaitForChild("Remote")
local module = {}
module.summon = function(name, pos)
print("sfs")
local monster = SerStorage.Monster[name]:Clone()
local torso = monster:WaitForChild("Torso")
torso.FrontSurface = Enum.SurfaceType.SmoothNoOutlines
torso.Transparency = 1
monster.Parent = workspace
monster:MoveTo(pos)
monster:MakeJoints()
local parts = monster:GetChildren()
for _,v in next, parts do
if v ~= torso then
local cV = CFrame.new(v.Position)
local weld = Instance.new("Weld")
weld.Name = "LimbWeld"
weld.Part0 = v
weld.Part1 = torso
weld.C0 = v.CFrame:inverse()*cV
weld.C1 = torso.CFrame:inverse()*cV
weld.Parent = v
v.Anchored = false
end
end
torso.Anchored = false
local human = Instance.new("Humanoid", monster)
human.HipHeight = 2
human.Died:connect(function()
local topContrib = nil
local topValue = 0
for _,v in next, human:GetChildren() do
if v:IsA("NumberValue") and v.Value > topValue then
topContrib = v.Name:sub(2)
topValue = v.Value
end
end
if topContrib ~= nil then
local player = Players:FindFirstChild(topContrib)
if player then
remote:FireClient(player, "LootDrop", name, torso.Position)
end
end
end)
return monster
end
return module
