I made a tool that plays a “slap” animation on your character, and damages anything touching their right hand. I split this feature into two scripts to ensure it replicates across the server.
Here are both scripts:
-- SlapScript (LocalScript, Tool)
local tool = script.Parent
local anim = script:WaitForChild("SlapAnim")
local character
local hum
local player = game.Players.LocalPlayer
local slapUpdateEvent = game.ReplicatedStorage.UpdateSlap
local RESET_TIME = 0.5
local debounce = false
local SLAP_DMG = 5
tool.Equipped:Connect(function()
character = tool.Parent
hum = character:WaitForChild("Humanoid")
end)
tool.Unequipped:Connect(function()
character = nil
end)
tool.Activated:Connect(function()
if not debounce then
debounce = true
hum.WalkSpeed = 0
slapUpdateEvent:FireServer(hum, anim, SLAP_DMG)
script.Slap:Play()
script.Scream:Play()
wait(RESET_TIME) -- Wait for reset duration
hum.WalkSpeed = game.StarterPlayer.CharacterWalkSpeed
debounce = false
end
end)
And the second:
-- UpdateSlap (Script, ServerScriptService)
game.ReplicatedStorage.UpdateSlap.OnServerEvent:Connect(function(player, hum, anim, SLAP_DMG)
local animTrack = hum:LoadAnimation(anim)
animTrack.Priority = Enum.AnimationPriority.Action
animTrack:Play()
local debounce = false
local slapCount = 0
hum.Parent.RightHand.Touched:Connect(function(hit)
slapCount += 1
if hit.Parent:FindFirstChild("Humanoid") and not debounce then
debounce = true
if hit.Parent.Humanoid.Health > 0 then
hit.Parent.Humanoid:TakeDamage(SLAP_DMG)
game.ReplicatedStorage.PlayerStats[player.Name].Slaps.Value += 0.5
animTrack.Stopped:Wait()
debounce = false
slapCount = 0
end
end
end)
end)
To mediate this, I halved the damage and points for each slap. However, this is not a permanent solution, because it makes the game look janky and could cause problems later.