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)
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.