Invisible Player

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:

Will be grateful if you help me to understand why it happens.

15 Likes

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

4 Likes

Other player takes damage from common script, which is inside the tool

3 Likes

Here is the tool 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 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)
5 Likes

that second if statement doesnt really prevent multiple hits though
is that a server script or a local script

3 Likes

That is a server script, not local

3 Likes

okay so the other player becomes invisible after they kill you?

1 Like

yes, the other player becomes visible again if he resets character

1 Like

can you provide client script of that sword (if you even have client script inside the sword)

1 Like

i do not have a client script inside the sword, only server

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

1 Like

do you have some scripts that change BasePart.Transparency?

i do not have scripts, that change character’s parts transparency

sooo, it fixed the problem of visibility after kill, but remained another: after rejoining other player also is invisible

May this server script cause this problem?

local repStorage = game:GetService("ReplicatedStorage")
local players = game.Players:GetPlayers()

local respawnEvent = repStorage.RespawnEvent

game.Players.PlayerAdded:Connect(function(player)
	player:LoadCharacter()
end)

respawnEvent.OnServerEvent:Connect(function(player)
	player:LoadCharacter()
end)

do you have CharacterAutoLoads set to false in Players?

1 Like

no, CharacterAutoLoads set to true in Players

if you have a manual spawning script you better keep that off

I would recommend to remove that .PlayerAdded in that case because its gonna load automaticially

1 Like

Okay, i will try two your variants.