Last days i can’t fix a bug, that makes another player invisible, if this player kills me by sword. Only when he does the character reset, he again becomes visible. I can not understand why that happends.
Here is screenshot, where you can see, how it looks:
if the other player is taking damage from local script then the changes of his health points and humanoid state will be only local for you and not the server and thus not the other player
local Debounce = false
local tool = script.Parent
local Handle = tool:WaitForChild("Handle")
local hitbox = tool.SwordTestModel:WaitForChild("Hitbox")
local Model = tool:WaitForChild("SwordTestModel")
local playersHit = {}
local slash = script:WaitForChild("sword1")
local sound = script.sword_swing1
tool.Activated:Connect(function()
if Debounce == false then
local hum = tool.Parent:WaitForChild("Humanoid")
local animTrack = hum:LoadAnimation(slash)
Debounce = true
animTrack:Play()
sound:Play()
wait(1)
Debounce = false
end
end)
hitbox.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and hit.Parent ~= tool.Parent then
if Debounce == true and playersHit[hit.Parent] == nil then
hit.Parent:FindFirstChild("Humanoid"):TakeDamage(25)
local hum = hit.Parent:FindFirstChild("Humanoid")
playersHit[hit.Parent] = true
if hum.Health < 1 then
local plr = game.Players:GetPlayerFromCharacter(script.Parent.Parent)
plr.leaderstats.Kills.Value = plr.leaderstats.Kills.Value +1
plr.leaderstats.Coins.Value = plr.leaderstats.Coins.Value + math.random(1, 3)
plr.leaderstats.ExP.Value = plr.leaderstats.ExP.Value + math.random(1, 3)
if hum.Health < 1 then -- prevent from multiple hits
plr.leaderstats.Kills.Value = plr.leaderstats.Kills.Value +0
plr.leaderstats.Coins.Value = plr.leaderstats.Coins.Value +0
plr.leaderstats.ExP.Value = plr.leaderstats.ExP.Value +0
end
return
end
wait(1)
playersHit[hit.Parent] = nil
end
end
end)
let me make some things more efficient in this script
local Debounce = false
local tool = script.Parent
local Handle = tool:WaitForChild("Handle")
local hitbox = tool.SwordTestModel:WaitForChild("Hitbox")
local Model = tool:WaitForChild("SwordTestModel")
local playersHit = {}
local slash = script:WaitForChild("sword1")
local sound = script.sword_swing1
tool.Activated:Connect(function()
if Debounce == false then
local hum = tool.Parent:WaitForChild("Humanoid")
local animTrack = hum:LoadAnimation(slash)
Debounce = true
animTrack:Play()
sound:Play()
wait(1)
Debounce = false
end
end)
hitbox.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and hit.Parent ~= tool.Parent then
if Debounce == true and not playersHit[hit.Parent] then
local hum = hit.Parent:FindFirstChild("Humanoid")
hum:TakeDamage(25)
playersHit[hit.Parent] = true
if hum.Health <= 0 then
local plr = game.Players:GetPlayerFromCharacter(script.Parent.Parent)
plr.leaderstats.Kills.Value = plr.leaderstats.Kills.Value +1
plr.leaderstats.Coins.Value = plr.leaderstats.Coins.Value + math.random(1, 3)
plr.leaderstats.ExP.Value = plr.leaderstats.ExP.Value + math.random(1, 3)
end
task.wait(1)
playersHit[hit.Parent] = nil
end
end
end)
i dont think sword script is causing such a behaviour it might be something else