✓ Accepted answer
There's a few things that are wrong with this script so let's start from scratch
First let's set the monster's variable
local monster = workspace.Monster
Next let's set up a died event
monster:WaitForChild("Humanoid").Died:connect(function()
end)
Next getting the player who killed him,
Most weapons have a tagging script built into them to record kills/deaths for character stats. You can utilize this feature to find the killer.
usually the tag's value is the player.
But if your weapon doesn't have this feature then you'll have to create it in your weapon.
monster:WaitForChild("Humanoid").Died:connect(function()
local tag = monster.Humanoid:findFirstChild("creator")
if tag then
end
end)
Next let's set up our chance
monster:WaitForChild("Humanoid").Died:connect(function()
local tag = monster.Humanoid:findFirstChild("creator")
if tag and tag.Value then
local chance=math.random(1,5)
if chance==2 then
end
end
end)
And now give the player the weapons if he doesn't have them
monster:WaitForChild("Humanoid").Died:connect(function()
local tag = monster.Humanoid:findFirstChild("creator")
if tag and tag.Value then
local chance=math.random(1,5)
if chance==2 then
if tag.Value.Backpack:FindFirstChild("GrassMace")==nil then
local wep = game.Lighting.GrassMace:Clone()
wep.Parent=tag.Value.Backpack
end
end
end
end)
No need to Destroy the script if the script is located inside the monster because it will be removed with the rest of the model and we don't need to clone the weapon to starterpack
Final Form:
local monster = workspace.Monster
monster:WaitForChild("Humanoid").Died:connect(function()
local tag = monster.Humanoid:findFirstChild("creator")
if tag and tag.Value then
local chance=math.random(1,5)
if chance==2 then
if tag.Value.Backpack:FindFirstChild("GrassMace")==nil then
local wep = game.Lighting.GrassMace:Clone()
wep.Parent=tag.Value.Backpack
end
end
end
end)
2 comments
put the random number and the if statement inside of the function instead of outside. Because currently line 22 is looking for a function that may not exist.
@SchonXIV, it says "Monsters" not "Players" in line 1... Something to think about.