Ah yes yet another discussion about swords. I have a sword script and inside is a function where if something is killed +1 souls is added to the leader boards. Though there are different types of mobs in my game that I want to give a different amount of souls on death. For example a chicken gives 2 souls while a frog gives 4. I already tried this with my script though it didn’t work.
local tool = script.Parent
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local function OnTouch(partOther)
if db1 then
if dbAnim then
local character = partOther.Parent
local humanOther = character:FindFirstChild("Humanoid")
if not humanOther then return end
if humanOther.Parent == tool then return end
local player = Players:GetPlayerFromCharacter(character)
if player and (player == Player or IsTeamMate(Player, player)) then
return
end
UntagHumanoid(humanOther)
TagHumanoid(humanOther, Player)
humanOther:TakeDamage(damage)
db1 = false
end
end
end
local InputService = game:GetService("UserInputService")
local InputType = Enum.UserInputType
local animation = nil
local slashAnimation = nil
tool.Equipped:Connect(function()
animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://7132227504"
slashAnimation = humanoid:LoadAnimation(animation)
end)
tool.Unequipped:Connect(function()
animation:Destroy()
slashAnimation = nil
end)
local debounce = false
InputService.InputBegan:Connect(function(input, processed)
if input.UserInputType == InputType.MouseButton1 and slashAnimation and not processed then
if debounce == false then
debounce = true
slashAnimation:Play()
local Connection
local tool = script.Parent
local function onTouch(partOther) --The function that gives souls
local humanOther = partOther.Parent:FindFirstChild("Humanoid")
if not humanOther then return end
if humanOther.Parent == tool then return end
humanOther:TakeDamage(5)
if game.humanOther.Health <= 0 then
player.leaderstats.Souls.Value = player.leaderstats.Souls.Value + 1
humanOther.Parent:Destroy()
end
end
Connection = tool.Handle.Touched:Connect(onTouch)
slashAnimation.Stopped:Wait()
debounce = false
Connection:Disconnect()
wait(.2)
debounce = false
end
end
end)