How to check if the sloop ended

Im tyring to fire the event after the character turns invisible but it the character is still fully invisable. What im tyring to do is when the the event is fired the character is inviable to other players but half invisable to themselves.

first event:

game.ReplicatedStorage.Invis.OnServerEvent:Connect(function(plr)
	local Character = plr.Character
	for i,v in pairs(Character:GetDescendants()) do -- loop through everything in the character
		if v:IsA("BasePart") or v:IsA("Decal") then -- if it is a part
			v.Transparency = 1 -- make it invisible
			game.ReplicatedStorage.Invisplr:FireClient(plr)
		end
	end
end)

second event (in local script):

game.ReplicatedStorage.Invisplr.OnClientEvent:Connect(function(plr)
	local Character = plr.Character
	for i,v in pairs(Character:GetDescendants()) do -- loop through everything in the character
		if v:IsA("BasePart") or v:IsA("Decal") then -- if it is a part
			v.Transparency = 0.5
		end
	end
end)

I think your looking for LocalTransparencyModifier You can find out more information about it here

1 Like

so I would i incorperate it into my script?

Instead of Transparency try replacing it with LocalTransparencyModifier I linked the documentation in my last comment. Read it please.

Thankyou but it still does not work, I changed it on the client side script because it said it changes on the client side. I might be wrong about that though.

Are you trying to make a specific player invisible? For example other players can’t see them, but they can see a translucent version of themselves or in other words their transparency is 0.5.

Im tyring to make the local player half inviable or become a ghost (model) and everyone else see them as invible

This is what i would put on the client:

local characterTransparencyConnections = {}
local character = game.Players.LocalPlayer.Character

-- use stopTransparencyConnection() to stop it from changing the transparency to 0.5
function stopTransparencyConnection()
    for _, connection in pairs(characterTransparencyConnections) do
        if connection.Connected then
            connection:Disconnect()
        end
    end
end

for _, part in pairs(character:GetDescendants()) do
	if part:IsA("BasePart") or part:IsA("Decal") then -- if it is a part
        part.LocalTransparencyModifier = 0.5

        table.insert(characterTransparencyConnections, part:GetPropertyChangedSignal("LocalTransparencyModifier"):Connect(function()
            part.LocalTransparencyModifier = 0.5
        end))
    end
end

game.ReplicatedStorage.Invis:FireServer()

This is what i would put on the server:

game.ReplicatedStorage.Invis.OnServerEvent:Connect(function(plr)
	local Character = targetPlr.Character
	for i,v in pairs(Character:GetDescendants()) do -- loop through everything in the character
		if v:IsA("BasePart") or v:IsA("Decal") then -- if it is a part
			v.Transparency = 1
		end
	end
end)

you dont need the invisplr remote because transparency replicates to all clients

Thankyou but it is not working, I did put the local script in server script service if that has anythign to do with it.

Wait you never fired the invis plr

Clients cannot access LocalScripts in ServerScriptService as ServerScriptService is a service for only the server, and not the client. Putting the localscript in something like starterplayerscripts or replicatedstorage should fix it.

invisplr remote is not needed as transparency property does get replicated to all clients

So the player spawns in as 0.5 transparent I want it so when Invis plr is fired on the serverside to be connected on the plrs side and then go 0.5 transparent, you fire it on the client side and it is reciveing nothing. But I do not know where to put it on the server side.

yes, if you just put it as a standalone script, the player will spawn half transparent. The code i provided you with is supposed to be incorporated into the code where you fire the invis remote. In this case, you fire the remote once you click a TextButton that says “Invis”. So to incorporate this, you need to find where you handle the click of the TextButton and replace the old code with the code i provided you with.

Ok thankyou, but I ran into another issue whener the invisplr is fired it does not turn the player 0.5

local characterTransparencyConnections = {}
local character = game.Players.LocalPlayer.Character

function stopTransparencyConnection()
	for _, connection in pairs(characterTransparencyConnections) do
		if connection.Connected then
			connection:Disconnect()
		end
	end
end
-- use stopTransparencyConnection() to stop it from changing the transparency to 0.5
game.ReplicatedStorage.Invisplr.OnClientEvent:Connect(function(plr)

	print("opasd")
	for _,v  in pairs(character:GetDescendants()) do
		if v:IsA("BasePart") or v:IsA("Decal") then -- if it is a part
			v.LocalTransparencyModifier = 0.5

			table.insert(characterTransparencyConnections, v:GetPropertyChangedSignal("LocalTransparencyModifier"):Connect(function()
				v.LocalTransparencyModifier = 0.5
			end))
		end
	end
	
end)

i woudn’t recommend using Invisplr remote as it would create more back and forwards between the server and client. Instead i would recommend adding the lines of code i provided you with right BEFORE you fire the Invis remote

Then what should I do because when the player loads it makes the player half invisalble

where do you detect when the invis button is clicked?

The local script is in the button

script.Parent.MouseButton1Click:Connect(function()
	game.ReplicatedStorage.Invis:FireServer(game.Players.LocalPlayer)
	game.ReplicatedStorage.Invisplr:FireServer(game.Players.LocalPlayer)
end)

great so replace those 4 lines of code with this:

local characterTransparencyConnections = {}
-- use stopTransparencyConnection() to stop it from changing the transparency to 0.5
function stopTransparencyConnection()
    for _, connection in pairs(characterTransparencyConnections) do
        if connection.Connected then
            connection:Disconnect()
        end
    end
end

script.Parent.MouseButton1Click:Connect(function()
    local character = game.Players.LocalPlayer.Character
  
    for _, part in pairs(character:GetDescendants()) do
        if part:IsA("BasePart") or part:IsA("Decal") then -- if it is a part
            part.LocalTransparencyModifier = 0.5
    
            table.insert(characterTransparencyConnections, part:GetPropertyChangedSignal("LocalTransparencyModifier"):Connect(function()
                part.LocalTransparencyModifier = 0.5
            end))
        end
    end
    
    game.ReplicatedStorage.Invis:FireServer()
end)