As the title says, my script will not remove the other player’s health who get hit, and will not even increase their own leaderstat for some reason.
Any help is appreciated
local Default_Ball = game.Workspace.DefaultBall
local Tool = script.Parent
local Player = script.Parent.Parent
local Character = Player.Character
local Humanoid = Character.Humanoid
local leaderstat = Player:WaitForChild("leaderstats")
-- Ball
local Ball = script.Parent.Default -- Change according to ball name
local character = Tool.Parent
-- Sound
local HitSound = Instance.new("Sound")
HitSound.Parent = Ball
HitSound.SoundId = "8060079174" -- Change to a heavy hit if damage is more then 20, if higher then 80 then do a VERY heavy hit.
HitSound.Volume = 10
HitSound.RollOffMaxDistance = 30
HitSound.RollOffMinDistance = 5
-- Settings
local debounce = false
Ball.Touched:Connect(function(hit)
wait(0.05)
local enemyplayer = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if not debounce then
debounce = true
enemyplayer.Character.Humanoid.Health = enemyplayer.Character.Humanoid.Health - 14 -- Change according to ball
leaderstat.Smacks.Value = leaderstat.Smacks.Value + 1
HitSound:Play()
wait(2)
debounce = false
end
end)
If I were to make it a localscript, it would only effect the client, so if they hit a player and killed them, they will show up dead ONLY on their screen.
Also that script doesn’t work
local Tool = script.Parent
local Player = script.Parent.Parent.Parent
local Character = Player.Character
local Humanoid = Character.Humanoid
local HitScript = Tool.HitScript
-- Ball
local Ball = script.Parent.DefaultBall
local character = Tool.Parent
-- Animation
local Animation = Instance.new("Animation")
Animation.AnimationId = "rbxassetid://13962251515"
-- Settings
local debounce = false -- Cooldown
Animation.Parent = Humanoid.Animator
Tool.Activated:Connect(function(activated)
local HitAnimPlay = Humanoid:LoadAnimation(Animation)
if not debounce then
debounce = true
HitAnimPlay:Play()
HitScript.Enabled = true
wait(2)
HitScript.Enabled = false
debounce = false
end
end)
Hit script
local Default_Ball = game.Workspace.DefaultBall
local Tool = script.Parent
local Player = script.Parent.Parent
local Character = Player.Character
local Humanoid = Character.Humanoid
local leaderstat = Player:WaitForChild("leaderstats")
-- Ball
local Ball = script.Parent.DefaultBall -- Change according to ball name
local character = Tool.Parent
-- Sound
local HitSound = Instance.new("Sound")
HitSound.Parent = Ball
HitSound.SoundId = "8060079174" -- Change to a heavy hit if damage is more then 20, if higher then 80 then do a VERY heavy hit.
HitSound.Volume = 10
HitSound.RollOffMaxDistance = 30
HitSound.RollOffMinDistance = 5
-- Settings
local debounce = false
Ball.Touched:Connect(function(hit)
wait(0.05)
local enemyplayer = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if not debounce then
debounce = true
enemyplayer.Character.Humanoid.Health = enemyplayer.Character.Humanoid.Health - 14 -- Change according to ball
leaderstat.Smacks.Value = leaderstat.Smacks.Value + 1
HitSound:Play()
wait(2)
debounce = false
end
end)
The part that give the tool turns on the script “script that turns on the hit script”
I really hate scripts that disable and enable other scripts depending on their state; its just an unreliable and ugly practice. A better way to do this would be to combine both scripts into one and when the tool is activated set a variable called isActivated to true, and inside the Touched event run a check whether isActivated is false if it is then return from the function
try this in the “script that enabled the hit script”
-- put me at line 3
local Player,Character,Humanoid
-- put me at bottom of script
Tool.Equipped:Connect(function()
Character = Tool.Parent
Player = game.Players:GetPlayerFromCharacter(Character)
Humanoid = Character:FindFirstChildOfClass("Humanoid")
end)