Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why doesn't player get visible again?

When the tool is equipped, it will make the player invisible and invincible, when it is unequipped again, it will make the player visible again. But, the player doesn't turn normal again after unequipping the tool.

script.Invincible.OnServerEvent:Connect(function(player, tool)
	local function makeInvisible()
	
	for i,v in pairs(player.Character:GetChildren()) do
		if v.ClassName == "MeshPart" or v.ClassName == "Part" then
			v.Transparency = 0.5
		end
		
	end
	
	
end

	player.Character.Humanoid.MaxHealth = math.huge
	player.Character.Humanoid.Health = math.huge
	player.Character.HumanoidRootPart.Transparency = 1
	makeInvisible()
end)

script.RemoveInvincible.OnServerEvent:Connect(function(player, tool)
		local function makeVisible()
			for i,v in pairs(player.Character:GetChildren()) do
		if v.ClassName == "MeshPart" or v.ClassName == "Part" then
			v.Transparency = 0
		end
		
	end
	
	player.Character.Humanoid.MaxHealth = 100
	player.Character.Humanoid.Health = 100
	makeVisible()

	end
end)

2 comments

0

Where's the localscript? So we see what's going on :D

0

Are you sure the RemoveInvincible event gets fired? Try adding a print at the top of its handler

1 answer

####Side note: please indent your code properly, it was extremely hard to find your problem.

###The problem is very simple. You were recursively calling the function, which is valid, but you didn't call the function itself. Simply add a call to makeInvisible and makeInvisible, and problem solved.

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local function makeInvisible(player)
    for i,v in pairs(player.Character:GetChildren()) do
        if v:IsA("BasePart") then -- use inheritance! the Part and MeshPart class inherit BasePart
            v.Transparency = 0.5
        end
    end
    player.Character.Humanoid.MaxHealth = math.huge
    player.Character.Humanoid.Health = math.huge
end
   
local function makeVisible(player)
    for i,v in pairs(player.Character:GetChildren()) do
        if v:IsA("BasePart") then
            v.Transparency = 0
        end
    end
    player.Character.Humanoid.MaxHealth = 100
    player.Character.Humanoid.Health = 100
end

-- You should put the remotes in ReplicatedStorage
ReplicatedStorage.Invincible.OnServerEvent:Connect(makeInvisible)
ReplicatedStorage.RemoveInvincible.OnServerEvent:Connect(makeVisible)
-- Connect the functions! They are called when the event is fired.

1 comment

0

Wow. Interesting.

This discussion is preserved as it was. New answers, comments, and votes are closed.