I have an NPC that drops a big glowing chest when it dies. But the problem is that the NPC will only fight other players if it is touched by them first, which means that players can just use ranged attacks to kill the NPC without a fight. When the NPC is touched, a value inside of it named "Target" , gets the value changed to the name of the player that touched it. For example, if Player1 touches the NPC, the value is then changed to Player1. Simple. How do I make this script only drop the chest when the Target value actually has something assigned to it?
function onDied()
for i =1,script.GoldCount.Value do
local xp = Instance.new("Part")
xp.Parent = game.Workspace
xp.Position = script.Parent.Parent.Torso.Position + Vector3.new(math.random(1,4),3,math.random(1,4))
xp.Shape = 1
xp.BrickColor = BrickColor.new("Bright yellow")
local z = Instance.new("SpecialMesh", xp)
z.MeshType = "Sphere"
z.MeshId = "http://www.roblox.com/asset/?id=23723701"
z.Scale = Vector3.new(3, 3, 3)
xp.Reflectance = 0.3
xp.Transparency = 0
local zz = Instance.new("PointLight")
zz.Range = 60
zz.Brightness = 60
zz.Color = Color3.new(255,255,255)
zz.Parent = xp
xp.Size = Vector3.new(3, 3, 3)
local clone = script.Increase:Clone()
clone.Disabled = false
clone.Parent = xp
end
end
script.Parent.Died:connect(onDied)
