To be able to fully make a player invisible and THEN visible if the button is pressed, again.
The issue:
I cannot work this script no matter what I try:
Server script:
game.ReplicatedStorage.Invisible.OnServerEvent:Connect(function(Player,status)
local char = Player.Character
if status == true then
reappear(char)
elseif status == false then
dissapear(char)
end
end)
function dissapear(char)
for _,part in next,char:GetDescendants() do
if part:IsA("BasePart") then
part.Transparency = 1
char.Head.face.Transparency = 1
end
end
end
function reappear(char)
for _,part in next,char:GetDescendants() do
if part:IsA("BasePart") then
part.Transparency = 0
char.HumanoidRootPart.Transparency = 1
char.Head.face.Transparency = 0
end
end
end
Inside the button, local script:
local player = game.Players.LocalPlayer
local invis = false
local char = player.Character
local user = script.Parent.Parent.PlayerUsername
script.Parent.MouseButton1Click:Connect(function()
if invis == false then
dissapear()
elseif invis == true then
reappear()
end
end)
function dissapear()
if invis == false then
game.ReplicatedStorage.Invisible:FireServer(user.Text, invis)
invis = true
script.Parent.Text = "Visible"
end
end
function reappear()
if invis == true then
game.ReplicatedStorage.Invisible:FireServer(user.Text, invis)
invis = false
script.Parent.Text = "Invisible"
end
end
Why are you firing the server with “user.Text”, you just want to have “invis” as the only parameter. The problem is that the server checks if “user.Text” == false or true", ir is neither of those so it never runs after those if statements.
Other code shouldn’t be the problem; you need to keep in mind that the top half of the code will run first, so you cannot reference something that hasn’t been defined as it hasn’t even run yet.
So when you fire a remoteevent, the first parameter is always the player who sent it. Try this:
local function checkForPlayers(name)
for I, v in pairs(game.Players:GetChildren()) do
if v.Name:lower() == name:lower() then
return v
end
end
end
game.ReplicatedStorage.Invisible.OnServerEvent:Connect(function(Playerwhosent,playername,status)
local player = checkForPlayers(playername)
if player then
local char = player.Character
if status == true then
reappear(char)
elseif status == false then
dissapear(char)
end
end
end)
function dissapear(char)
for _,part in next,char:GetDescendants() do
if part:IsA("BasePart") then
part.Transparency = 1
char.Head.face.Transparency = 1
end
end
end
function reappear(char)
for _,part in next,char:GetDescendants() do
if part:IsA("BasePart") then
part.Transparency = 0
char.HumanoidRootPart.Transparency = 1
char.Head.face.Transparency = 0
end
end
end
@walshuk The functions are global functions, because he doesn’t user “local” inside of them. Therefore, it ok to call them above where they are defined.