So I’m fixing up this old game that’s been broken due to filtering enabled and overall ROBLOX updates. This (SUPPOSED TO BE SIMPLE) sword script will not deal damage and I have no idea why. I’ve been at this for a few days and I still can’t figure it out. It’s a server script.
If anyone could point me in the right direction, I’d really appreciate it.
Code:
local HIT_DEBOUNCE_TIME = .5
local HIT_DAMAGE = 25
local humHitTimes = {}
function WaitForChild(parent, child)
while not parent:FindFirstChild(child) do wait() end
return parent[child]
end
function incrementScore(player)
local playerScoreTag = WaitForChild(player, "Score")
playerScoreTag.Value = playerScoreTag.Value + 1
end
local StateManager = WaitForChild(game.Workspace, "StateManager")
local TeamKillTag = WaitForChild(StateManager, "TeamKill")
local Handle=WaitForChild(script.Parent,'*Handle*')
function blow(hit)
if not hit then return end
if not script.Parent.Enabled then return end
local hitChar = hit.Parent
if not hitChar then return end
local hitHum = hitChar:FindFirstChild("Humanoid")
if not hitHum then return end
local vCharacter = script.Parent.Parent
if not vCharacter then return end
local vPlayer = game.Players:playerFromCharacter(vCharacter)
if not vPlayer then return end
local otherPlayer = game.Players:playerFromCharacter(hitChar)
if otherPlayer and (otherPlayer==vPlayer or not TeamKillTag.Value) then return end -- no self-killing (and TK only if it's duel-time)
local currTime = tick()
if not Handle.hit.IsPlaying then
Handle.hit.Pitch= math.random()+.5
Handle.hit:Play()
delay(.5,function() Handle.hit:Stop() end)
end
if not humHitTimes[hitHum] or humHitTimes[hitHum] < currTime - HIT_DEBOUNCE_TIME then
humHitTimes[hitHum] = currTime
if hitHum.Health > 0 and hitHum.Health <= HIT_DAMAGE then
if hitChar.Name ~= "Shredder" then
incrementScore(vPlayer)
else
-- killed the boss; start the death animation!
workspace.StateManager.ShredderManager.BossDeath:Invoke()
return
end
end
hitHum:TakeDamage(HIT_DAMAGE)
wait(.5)
end
end
Handle.Touched:Connect(blow)