Shards Per Kill Dummys

I have a weapon system but i want if you kill a dummy it gives you shards i wrote this

Server - leaderstats

game.Players.PlayerAdded:connect(function(player)
local leaderstats = Instance.new("Folder",player)
leaderstats.Name = "leaderstats"
leaderstats.Parent = player

local Shards = Instance.new("IntValue",leaderstats)
Shards.Name = "Shards"
Shards.Value = 0
Shards.Parent = leaderstats

local kills = Instance.new("IntValue",leaderstats)
kills.Name = "Kills"
kills.Value = 0
kills.Parent = leaderstats

local TimeAlive = Instance.new("IntValue",leaderstats)
TimeAlive.Name = "TimeAlive"
TimeAlive.Value = 0
TimeAlive.Parent = leaderstats



player.CharacterAdded:connect(function(character)
	character:WaitForChild("Humanoid").Died:connect(function(killed)
		local CreatorTag = character.Humanoid:FindFirstChild("creator")
		if CreatorTag and CreatorTag.Value then
			local stats = CreatorTag.Value:WaitForChild("leaderstats")
			stats["Shards"].Value = stats["Shards"].Value + 100
			stats["Kills"].Value = stats["Kills"].Value + 1  
			stats["TimeAlive"].Value = stats["TimeAlive"].Value + 50    
		end
	end)
end)

end)

and Local - Client Weapons

local Handle = Tool:waitForChild("Handle")
local Player = game.Players.LocalPlayer
local Character = workspace:waitForChild(Player.Name)
local Humanoid = Character:waitForChild("Humanoid")
local Mouse, Equipped, onAnimation, can, punching = Player:GetMouse(), false, false, true, false
local tweenService = game.TweenService
local tweenInfo = TweenInfo.new(1,Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
local IdleAnim, HitAnim
local server = script.Parent:WaitForChild("MeleeWeapon_Server")
local Module = require(Tool:WaitForChild("Setting"))
wait(1)
if Module.IdleAnimationID ~= nil then IdleAnim = Tool:waitForChild("IdleAnim") IdleAnim = Humanoid:LoadAnimation(IdleAnim) end
if Module.HitAnimationID ~= nil then HitAnim = Tool:waitForChild("HitAnim") HitAnim = Humanoid:LoadAnimation(HitAnim) end

function DamageGui(hum,damage)
	local gui = game.ReplicatedStorage.Resource.DamageBillboard:Clone()
	gui.DamageText.Text = tostring(damage)
	gui.Parent = hum.Parent.Head
	local tweenGoal = {Position = UDim2.new(0.5 + math.random(-4,4)/10, 0, .25, 0), TextTransparency = 1, TextStrokeTransparency = 1}
	local tween = tweenService:Create(gui.DamageText, tweenInfo, tweenGoal)
	tween:Play()
	tween.Completed:Connect(function() gui:Destroy() end)
end

Mouse.Button1Down:connect(function() 
	if Equipped and not onAnimation and not punching then
		punching = true 
		HitAnim:Play() 
		Handle.Hit:Play() 
		server.Damage:FireServer(0)
		onAnimation = true  
		wait(HitAnim.Length) 
		server.Damage:FireServer(1)
		punching = false 
		onAnimation = false
	end 
end)
Tool.Equipped:connect(function(TempMouse) Equipped = true if IdleAnim then IdleAnim:Play(nil,nil,Module.IdleAnimationSpeed) end end)
Tool.Unequipped:connect(function() Equipped = false if IdleAnim then IdleAnim:Stop() end end)
Humanoid.Died:connect(function() Equipped = false if IdleAnim then IdleAnim:Stop() end end)

Handle.Touched:Connect(function(hit)
	if onAnimation and hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name ~= Player.Name and hit.Parent.Humanoid.Health > 0 and can then
		if game.Players:FindFirstChild(hit.Parent.Name) and game.Players:FindFirstChild(hit.Parent.Name).Team ~= Player.Team then
			can = false 
			DamageGui(hit.Parent:FindFirstChild("Humanoid"),Module.BaseDamage)
			spawn(function() wait(.5) can = true end)
		end	
	end
end)

and the last one the server



```local Tool = script.Parent
local Module = require(Tool:WaitForChild("Setting"))
local can, onAnimation = true, false

if Module.IdleAnimationID ~= nil or Module.DualEnabled then
	local IdleAnim = Instance.new("Animation",Tool)
	IdleAnim.Name = "IdleAnim"
	IdleAnim.AnimationId = "rbxassetid://"..Module.IdleAnimationID
end
if Module.HitAnimationID ~= nil then
	local HitAnim = Instance.new("Animation",Tool)
	HitAnim.Name = "HitAnim"
	HitAnim.AnimationId = "rbxassetid://"..Module.HitAnimationID
end

function unEquipItems() script.Parent.Parent = game.Players:GetPlayerFromCharacter(script.Parent.Parent).Backpack end

script.Damage.OnServerEvent:Connect(function(plr,tipe)
	if tipe then
		if tipe == 0 then
			onAnimation = true
		else
			onAnimation = false
		end
	end
end)
script.Parent.Handle.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name ~= script.Parent.Parent.Name and hit.Parent.Humanoid.Health > 0 and can and onAnimation then
		can = false 
		hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - Module.BaseDamage
		spawn(function() wait(.5) can = true end)
	end
end)

while wait(.1) do 
	if script.Parent.Parent.Name ~= "Backpack" and script.Parent.Parent:FindFirstChild("Humanoid") and script.Parent.Parent.Humanoid.Sit == true then unEquipItems() end 
end
1 Like

For the function on the server where you take away health from the dummy, check if the new health of the dummy is less than or equal to 0. Then if it is, add shards to the player.

Not sure how to do that :frowning:

Can you reshare your other code from the posts that you deleted. I have class right now but in around 10 minutes I can show you how to do it.

1 Like

Ok let me reshare the code :sweat_smile:

Weapon Server

	local Module = require(Tool:WaitForChild("Setting"))
	local can, onAnimation = true, false

	if Module.IdleAnimationID ~= nil or Module.DualEnabled then
		local IdleAnim = Instance.new("Animation",Tool)
		IdleAnim.Name = "IdleAnim"
		IdleAnim.AnimationId = "rbxassetid://"..Module.IdleAnimationID
	end
	if Module.HitAnimationID ~= nil then
		local HitAnim = Instance.new("Animation",Tool)
		HitAnim.Name = "HitAnim"
		HitAnim.AnimationId = "rbxassetid://"..Module.HitAnimationID
	end

	function unEquipItems() script.Parent.Parent = game.Players:GetPlayerFromCharacter(script.Parent.Parent).Backpack end

	script.Damage.OnServerEvent:Connect(function(plr,tipe)
		if tipe then
			if tipe == 0 then
				onAnimation = true
			else
				onAnimation = false
			end
		end
	end)
	script.Parent.Handle.Touched:Connect(function(hit)
		if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name ~= script.Parent.Parent.Name and hit.Parent.Humanoid.Health > 0 and can and onAnimation then
			can = false 
			hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - Module.BaseDamage
			spawn(function() wait(.5) can = true end)
		end
	end)

	while wait(.1) do 
		if script.Parent.Parent.Name ~= "Backpack" and script.Parent.Parent:FindFirstChild("Humanoid") and script.Parent.Parent.Humanoid.Sit == true then unEquipItems() end 
	end

Weapon Local

local Handle = Tool:waitForChild("Handle")
local Player = game.Players.LocalPlayer
local Character = workspace:waitForChild(Player.Name)
local Humanoid = Character:waitForChild("Humanoid")
local Mouse, Equipped, onAnimation, can, punching = Player:GetMouse(), false, false, true, false
local tweenService = game.TweenService
local tweenInfo = TweenInfo.new(1,Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
local IdleAnim, HitAnim
local server = script.Parent:WaitForChild("MeleeWeapon_Server")
local Module = require(Tool:WaitForChild("Setting"))
wait(1)
if Module.IdleAnimationID ~= nil then IdleAnim = Tool:waitForChild("IdleAnim") IdleAnim = Humanoid:LoadAnimation(IdleAnim) end
if Module.HitAnimationID ~= nil then HitAnim = Tool:waitForChild("HitAnim") HitAnim = Humanoid:LoadAnimation(HitAnim) end

function DamageGui(hum,damage)
	local gui = game.ReplicatedStorage.Resource.DamageBillboard:Clone()
	gui.DamageText.Text = tostring(damage)
	gui.Parent = hum.Parent.Head
	local tweenGoal = {Position = UDim2.new(0.5 + math.random(-4,4)/10, 0, .25, 0), TextTransparency = 1, TextStrokeTransparency = 1}
	local tween = tweenService:Create(gui.DamageText, tweenInfo, tweenGoal)
	tween:Play()
	tween.Completed:Connect(function() gui:Destroy() end)
end

Mouse.Button1Down:connect(function() 
	if Equipped and not onAnimation and not punching then
		punching = true 
		HitAnim:Play() 
		Handle.Hit:Play() 
		server.Damage:FireServer(0)
		onAnimation = true  
		wait(HitAnim.Length) 
		server.Damage:FireServer(1)
		punching = false 
		onAnimation = false
	end 
end)
Tool.Equipped:connect(function(TempMouse) Equipped = true if IdleAnim then IdleAnim:Play(nil,nil,Module.IdleAnimationSpeed) end end)
Tool.Unequipped:connect(function() Equipped = false if IdleAnim then IdleAnim:Stop() end end)
Humanoid.Died:connect(function() Equipped = false if IdleAnim then IdleAnim:Stop() end end)

Handle.Touched:Connect(function(hit)
	if onAnimation and hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name ~= Player.Name and hit.Parent.Humanoid.Health > 0 and can then
		if game.Players:FindFirstChild(hit.Parent.Name) and game.Players:FindFirstChild(hit.Parent.Name).Team ~= Player.Team then
			can = false 
			DamageGui(hit.Parent:FindFirstChild("Humanoid"),Module.BaseDamage)
			spawn(function() wait(.5) can = true end)
		end	
	end
end)

Change this:

Change to this:

script.Parent.Handle.Touched:Connect(function(hit)
		if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name ~= script.Parent.Parent.Name and hit.Parent.Humanoid.Health > 0 and can and onAnimation then
			can = false 
			hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - Module.BaseDamage
            if hit.Parent.Humanoid.Health <= 0 then --give them shards if dummy is dead
                local player = game.Players:GetPlayerFromCharacter(script.Parent.Parent) 
                player.Shards.Value += 50 --change to however many shards you want to give
            end
			spawn(function() wait(.5) can = true end)
		end
	end)

Thank you so much :smiley: it works

1 Like

wait but is there a way for it too only give if its a dummy not a player like if you kill a pirate it gives you but not a player

Yes, you can check if it is a player that you hit by using game.Players:GetPlayerFromCharacter. Something like this:

script.Parent.Handle.Touched:Connect(function(hit)
		if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name ~= script.Parent.Parent.Name and hit.Parent.Humanoid.Health > 0 and can and onAnimation then
			can = false 
			hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - Module.BaseDamage
            local TargetPlayer = game.Players:GetPlayerFromCharacter(hit.Parent) --see if the character that was hit was a player's character
            if hit.Parent.Humanoid.Health <= 0 and not TargetPlayer then --give them shards if dummy is dead and if the target isn't a player
                local player = game.Players:GetPlayerFromCharacter(script.Parent.Parent) 
                player.Shards.Value += 50 --change to however many shards you want to give
            end
			spawn(function() wait(.5) can = true end)
		end
	end)

[
:clap::clap:Thank you so much a can now work on AI

1 Like

No problem, I’m glad I could help!! :slight_smile:

1 Like