In the answer is code that you should be able to paste into the died function, something like
local hide = true --Whether to hide, can be manipulated
local orignalTransparency = {}--Store original transparency
local function checkPart(part) --This will set the transparency of every part
for a,b in pairs(part:GetChildren()) do
checkPart(b) --If there are more parts, also set the transparency for them too
end
if part:IsA("BasePart") or part:IsA("Decal") then--If the object is a part or decal, set it's transparency. (Face is a decal)
if hide then --If we want to hide players, make their parts invisible
if not orignalTransparency[part] then--Store data for later if we want to undo the effect
orignalTransparency[part] = part.Transparency
end
part.Transparency = 1
else --If we don't want to hide, set the transparency back to normal
if orignalTransparency[part] then --If we stored it
part.Transparency = orignalTransparency[part] --Set it
orignalTransparency[part] = nil --Remove reference because we do not need it anymore, prevents memory leaks
end
end
end
end
local players = game:GetService("Players")
local localPlayer = players.LocalPlayer
game:GetService("RunService").RenderStepped:Connect(function() --Every frame, set transparency
--Iterate through players to make them invisible
for i,v in pairs(players:GetPlayers()) do --Go through every player
if v ~= localPlayer then --This makes sure we don't make ourself invisble. Remove this for everyone.
local char = v.Character
if char then--If the character exists
checkPart(char)
end
end
end
--Prevent memory leaks, if a part does not exist anymore we do not need to reference it
for part,trans in pairs(orignalTransparency) do
if not part then
orignalTransparency[part] = nil
elseif not part.Parent then
orignalTransparency[part] = nil
end
end
end)
while true do --Testing functionality
hide = true
wait(2.5)
hide = false
wait(2.5)
end
You will have to modify it to fit, but it should work. Good luck!
game:GetService('Players').PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
print("i am alive")
character:WaitForChild("Humanoid").Died:Connect(function()
print(player.Name .. " has died!")
--code inside
local hide = true --Whether to hide, can be manipulated
local orignalTransparency = {}--Store original transparency
local function checkPart(part) --This will set the transparency of every part
for a,b in pairs(part:GetChildren()) do
checkPart(b) --If there are more parts, also set the transparency for them too
end
if part:IsA("BasePart") or part:IsA("Decal") then--If the object is a part or decal, set it's transparency. (Face is a decal)
if hide then --If we want to hide players, make their parts invisible
if not orignalTransparency[part] then--Store data for later if we want to undo the effect
orignalTransparency[part] = part.Transparency
end
part.Transparency = 1
else --If we don't want to hide, set the transparency back to normal
if orignalTransparency[part] then --If we stored it
part.Transparency = orignalTransparency[part] --Set it
orignalTransparency[part] = nil --Remove reference because we do not need it anymore, prevents memory leaks
end
end
end
end
local players = game:GetService("Players")
local localPlayer = players.LocalPlayer
game:GetService("RunService").RenderStepped:Connect(function() --Every frame, set transparency
--Iterate through players to make them invisible
for i,v in pairs(players:GetPlayers()) do --Go through every player
if v ~= localPlayer then --This makes sure we don't make ourself invisble. Remove this for everyone.
local char = v.Character
if char then--If the character exists
checkPart(char)
end
end
end
--Prevent memory leaks, if a part does not exist anymore we do not need to reference it
for part,trans in pairs(orignalTransparency) do
if not part then
orignalTransparency[part] = nil
elseif not part.Parent then
orignalTransparency[part] = nil
end
end
end)
while true do --Testing functionality
hide = true
wait(2.5)
hide = false
wait(2.5)
end
--end code inside
end)
end)
end)
If your game is based around it you could have a server sided BoolValue called āAliveā or something then when the player dies have it turn everyone with āAliveā equal to true invisible.
I need to do something similar to vampire diarie that when you die you appear on your body and only those who are dead can see each other, how could something like this be done? Sorry for so many questions
We could make the system work, so that only alive people can see alive and only dead people can see the dead. Let me throw together a script for it really quick.
game:GetService('Players').PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
print("i am alive")
character:WaitForChild("Humanoid").Died:Connect(function()
print(player.Name .. " has died!")
--code inside
local hide = true --Whether to hide, can be manipulated
local orignalTransparency = {}--Store original transparency
local function checkPart(part) --This will set the transparency of every part
for a,b in pairs(part:GetChildren()) do
checkPart(b) --If there are more parts, also set the transparency for them too
end
if part:IsA("BasePart") or part:IsA("Decal") then--If the object is a part or decal, set it's transparency. (Face is a decal)
if hide then --If we want to hide players, make their parts invisible
if not orignalTransparency[part] then--Store data for later if we want to undo the effect
orignalTransparency[part] = part.Transparency
end
part.Transparency = 1
else --If we don't want to hide, set the transparency back to normal
if orignalTransparency[part] then --If we stored it
part.Transparency = orignalTransparency[part] --Set it
orignalTransparency[part] = nil --Remove reference because we do not need it anymore, prevents memory leaks
end
end
end
end
local players = game:GetService("Players")
local localPlayer = players.LocalPlayer
game:GetService("RunService").RenderStepped:Connect(function() --Every frame, set transparency
--Iterate through players to make them invisible
for i,v in pairs(players:GetPlayers()) do --Go through every player
if v ~= localPlayer then --This makes sure we don't make ourself invisble. Remove this for everyone.
local char = v.Character
if char then--If the character exists
checkPart(char)
end
end
end
--Prevent memory leaks, if a part does not exist anymore we do not need to reference it
for part,trans in pairs(orignalTransparency) do
if not part then
orignalTransparency[part] = nil
elseif not part.Parent then
orignalTransparency[part] = nil
end
end
end)
while true do --Testing functionality
hide = true
wait(2.5)
hide = false
wait(2.5)
end
--end code inside
end)
end)
end)
Haha, np. I find myself working in circles all the time, checking something then realizing I did the wrong thing. I totally get it If it actually did work, you might want to mark it as the solution, so future people can find the answer. Good luck with your game!
Exactly the same thing happens to me ā¦ I have been working with lua for two weeks and many times I enter the circle but I have acquired some experience ā¦ you have to keep learning! Thanks for everything and much success to you too in everything!