Can't make player's characters transparent?

This seems to only happen with R15 characters in my game. When they join, I look through all the descendants of their character and set their transparency to something like 0.5, but this only works for R6 characters. Why is that?

can you show the script for the transparency

local Players = game:GetService("Players")
local ReplicatedFirst = game:GetService("ReplicatedFirst")
local RunService = game:GetService("RunService")

RunService.Stepped:Wait()
local transparency = ReplicatedFirst:WaitForChild("Config",5):WaitForChild("PlayerTransparency",5).Value

local function ghost(player)
	if player == Players.LocalPlayer then return end
	RunService.RenderStepped:Wait()
	for k,v in pairs(player.Character:GetDescendants()) do
		print(k,v)
		if pcall(function() return v.Transparency end) and v.Name ~= ("HumanoidRootPart") then
			v.Transparency = transparency
		end
	end
end

Players.PlayerAdded:Connect(function(player) 
	if player.Character then ghost(player.Character) end
	player.CharacterAppearanceLoaded:Connect(function() ghost(player) end)
end)

for k,v in pairs(Players:GetPlayers()) do
	ghost(v)
end

Let me know if you find anything… :confused:

is this a localscript, if it is, you don’t need playeradded because the localscript will be automatically put into the player

you can do something like:

local Players = game:GetService("Players")
local ReplicatedFirst = game:GetService("ReplicatedFirst")

local transparency = ReplicatedFirst:WaitForChild("Config",5):WaitForChild("PlayerTransparency",5).Value

local function ghost(player)
    if player then
        local character = player.Character or player.CharacterAdded:Wait()
        for _, child in pairs(character:GetDescendants()) do
            if child:IsA("BasePart") and child.Name ~= "HumanoidRootPart" then
                if not transparency then
                    transparency = .5
                end
                child.Transparency = tonumber(transparency) or .5
            end
        end
    end
end

for _, player in pairs(Players:GetPlayers()) do
    if player ~= Players.LocalPlayer then
        ghost(player)
    end
end

I suggest changing:

for _, player in pairs(Players:GetPlayers()) do
    if player ~= Players.LocalPlayer then
        ghost(player)
    end
end

into

for _, player in pairs(Players:GetPlayers()) do
    if player ~= Players.LocalPlayer then
        ghost(player)
        Players.PlayerAdded:Connect(function(character)
            ghost(player)
        end
    end
end

Players.PlayerAdded:Connect(function(player)
    if player ~= Players.LocalPlayer then
        ghost(player)
        Players.PlayerAdded:Connect(function(character)
            ghost(player)
        end
    end
end)

As now if a player respawns or a new player joins and respawns they become invisible as well.

The R15 players are still not transparent… This is strange. Is it not possible to change the Transparency of their body parts? :thinking:

Im pretty sure you can, because in Frosted studio’s infection game, there are ghost zombies.
Try making the parts into forcefield material

Because you put a value directly to ReplicatedFirst.Config.PlayerTransparency
and if the transparency value changes the variable doesn’t get changed as the variable isn’t holding the object value, but a number value. so what you gotta do:

For the variable:

local transparency = `ReplicatedFirst.Config.PlayerTransparency`

When calling the value:

transparency.Value

(But if you want the value to be constant keep it like you had it before)

I found the issue,
A few of the end’s didn’t have a ) behind them while they were calling from a function and I edited something else, that when the player joins they don’t get instantly ghosted, as their character didn’t load.
It should be this:

for _, player in pairs(Players:GetPlayers()) do
    ghost(player)
	player.CharacterAdded:Connect(function(character)
		ghost(player)
	end)
end

Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		ghost(player)
	end)
end)

Instead of the last thing I showed you, tho the message I made before might help too.

I got another edit to the ghost function, to check if the character of the player is even valid; the whole script; otherwise it would bug out if a player who is already in game doesn’t have a character.

local Players = game:GetService("Players")
local ReplicatedFirst = game:GetService("ReplicatedFirst")
local RunService = game:GetService("RunService")

RunService.Stepped:Wait()
local transparency = ReplicatedFirst:WaitForChild("Config",5):WaitForChild("PlayerTransparency",5)

local function ghost(player)
	if player == Players.LocalPlayer or player.Character == nil then return end
	RunService.RenderStepped:Wait()
	for k,v in pairs(player.Character:GetDescendants()) do
		print(k,v)
		if pcall(function() return v.Transparency end) and v.Name ~= ("HumanoidRootPart") then
			v.Transparency = transparency.Value
		end
	end
end

for _, player in pairs(Players:GetPlayers()) do
	ghost(player)
	player.CharacterAdded:Connect(function(character)
		ghost(player)
	end)
end

Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		ghost(player)
	end)
end)

You could even make it so that when the value changes you change the transparency of every player.

1 Like