So I saw this post and try the code and it work
but I want to make have a duration
like this bar :
when it runs out like this :
the player will be back visible
here’s the full code :
Server :
local tool = script.Parent
local RemoteFunction = Instance.new("RemoteFunction", game.ReplicatedStorage.Remotes)
RemoteFunction.Name = "ChangeVisibility"
local LastInvoke = {}
local Cooldown = 5
local CooldownForTrueOnly = true
RemoteFunction.OnServerInvoke = function(player, value)
local Found = nil
for i,v in pairs(LastInvoke) do
if v[1] == player.UserId then
Found = v
end
end
if Found then
if CooldownForTrueOnly then
if value then
if tick() - Found[2] >= Cooldown then
for i,v in pairs(LastInvoke) do
if v == Found then
v[2] = tick()
end
end
else
print("Visiblity Cooldown For: "..player.Name..", Time Left: "..math.ceil(Cooldown - (tick() - Found[2])).."s")
return {false, Cooldown - (tick() - Found[2])}
end
end
else
if tick() - Found[2] >= Cooldown then
for i,v in pairs(LastInvoke) do
if v == Found then
v[2] = tick()
end
end
else
print("Visiblity Cooldown For: "..player.Name..", Time Left: "..math.ceil(Cooldown - (tick() - Found[2])).."s")
return {false, Cooldown - (tick() - Found[2])}
end
end
else
table.insert(LastInvoke, {player.UserId, tick()})
end
local Character = player.Character or player.CharacterAdded:Wait()
if Character then
for i,v in pairs(Character:GetChildren()) do
if v:IsA("Accessory") then
if value then v.Handle.Transparency = 1 else v.Handle.Transparency = 0 end
else
if v.Name ~= "HumanoidRootPart" then
pcall(function()
if value then v.Transparency = 1 else v.Transparency = 0 end
end)
end
end
if v.Name == "Head" then
if value then v.face.Transparency = 1 else v.face.Transparency = 0 end
end
if v:IsA("Tool") then
if value then tool.Handle.Transparency = 1 else tool.Handle.Transparency = 0 end
end
end
end
return true
end
Client :
local enabled = false
script.Parent.Name = "Invisibility: Off"
script.Parent.Activated:Connect(function()
if enabled == false then
local result = game.ReplicatedStorage.Remotes:WaitForChild("ChangeVisibility"):InvokeServer(true)
if result == true then
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,false)
enabled = true
script.Parent.Name = "Invisibility: On"
elseif type(result) == "table" then
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,true)
script.Parent.Name = "Cooldown"
wait(result[2])
script.Parent.Name = "Invisibility: Off"
end
elseif enabled == true then
local result = game.ReplicatedStorage.Remotes:WaitForChild("ChangeVisibility"):InvokeServer(false)
if result == true then
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,true)
enabled = false
script.Parent.Name = "Invisibility: Off"
end
end
end)
game.Players.LocalPlayer.Character.Humanoid.Died:Connect(function()
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,true)
enabled = false
script.Parent.Name = "Invisibility: Off"
end)
if you guys have any idea how to do it please reply, thank you!