Hello again… yeah, again. This time I managed to solve the problem of him walking and applying damage all the time, the object in the end did not self-destruct. With everything, now the Code no longer wants to apply damage after I press C. I was trying to do a double check so that it would recognize if I was going to press the button or not, but it was to take it the same way. If anyone has a method I can resolve this damage conflict, I’d appreciate it.
Stomp:
local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local pisarEnabled = false -- Variable to control if the stomping is enabled
local kickAnimationId = "13874028312" -- Kick animation ID
local damageAmount = 100 -- Damage value to be applied
-- Function to apply damage to the object
local function ApplyDamageToObject(object)
local vidaDeObjetos = object:FindFirstChild("Vida de objetos")
if vidaDeObjetos then
ReplicatedStorage:WaitForChild("DamageServer"):FireServer(vidaDeObjetos, damageAmount) -- Sends the damage signal to the object with the damage value
end
end
-- Function to play the kick animation
local function PlayAnimation(animationId)
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://" .. animationId
local track = humanoid:LoadAnimation(animation)
track:Play()
return track
end
-- Function to toggle the stomping feature
local function TogglePisar()
if not pisarEnabled then
-- Enable stomping
pisarEnabled = true
humanoid.WalkSpeed = 0 -- Set the walk speed to 0
local kickAnimationTrack = PlayAnimation(kickAnimationId) -- Play the kick animation
kickAnimationTrack.Stopped:Connect(function()
pisarEnabled = false -- Disable stomping after the animation finishes
humanoid.WalkSpeed = 16 -- Restore the default walk speed
end)
end
end
-- Connect the toggle function to the C key input event
UserInputService.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.C then
TogglePisar()
end
end)
-- Function to check if a part is the right foot
local function IsRightFoot(part)
return part == humanoid.RightFoot or part:IsDescendantOf(humanoid.RightFoot)
end
-- Connect the damage function to triggering when the right foot touches an object only when stomping is enabled and the C key is pressed
character.DescendantAdded:Connect(function(descendant)
if IsRightFoot(descendant) then
descendant.Touched:Connect(function(part)
if pisarEnabled and UserInputService:IsKeyDown(Enum.KeyCode.C) then
local object = part.Parent
ApplyDamageToObject(object) -- Apply damage to the touched object
end
end)
end
end)
Health Object
local object = script.Parent
local health = object:FindFirstChild("Health")
if not health then
health = Instance.new("IntValue")
health.Name = "Health"
health.Value = 1
health.Parent = object
end
local canTouch = true
local function TakeDamage(damageAmount)
health.Value = health.Value - damageAmount
if health.Value <= 0 then
object:Destroy()
end
end
object.Touched:Connect(function(part)
local humanoid = part.Parent:FindFirstChildOfClass("Humanoid")
local player = game.Players:GetPlayerFromCharacter(part.Parent)
local character = player and player.Character
if humanoid and player and character then
local rightFoot = character:FindFirstChild("RightFoot")
if rightFoot and part == rightFoot then
end
end
end)