Localsided to Serversided Character Transparency

  1. What do you want to achieve?
    When Shift Hold:
    (Server) Local Player Transparency = 1
    (Client) Local Player Transparency = 0.5

When Shift Released:
(Server) Local Player Transparency = 0
(Client) Local Player Transparency = 0

  1. What is the issue?
    How do I grab character from a server script?

  2. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tried asking chatgpt to help but doesn’t seem to work. (Either the script waiting in loop, or something like can’t find child in players)
    Yes, I have searched the forum, turns out that people say its impossible to grab character from a server.

My Localscript:

local time_freeze = game.ReplicatedStorage.Time_Freeze

local plr = game:GetService("Players").LocalPlayer;
local char = plr.Character or plr.CharacterAdded:Wait();

local activation = game.ReplicatedStorage.Activate
local disable_activation = game.ReplicatedStorage.Disable

time_freeze.Changed:Connect(function()
	if time_freeze.Value == true then
		char.Head.Transparency = 0.5
		char.Torso.Transparency = 0.5
		plr.Character["Left Leg"].Transparency = 0.5
		plr.Character["Right Leg"].Transparency = 0.5
		plr.Character["Left Arm"].Transparency = 0.5
		plr.Character["Right Arm"].Transparency = 0.5

		activation:FireServer()
	end
	if time_freeze.Value == false then
		char.Head.Transparency = 0
		char.Torso.Transparency = 0
		plr.Character["Left Leg"].Transparency = 0
		plr.Character["Right Leg"].Transparency = 0
		plr.Character["Left Arm"].Transparency = 0
		plr.Character["Right Arm"].Transparency = 0

		disable_activation:FireServer()
	end
end)

My Serverscript:

local activation = game.ReplicatedStorage.Activate
local disable_activation = game.ReplicatedStorage.Disable

local function invisible()
	print("received")
	-- Code Here
end

local function disabled()
	print("ended")
	-- Code Here
end

disable_activation.OnServerEvent:Connect(disabled)
activation.OnServerEvent:Connect(invisible)

Server does respond:
image

First setting the Transparency on the Client to 0.5 and then with a Remote Event in the Server to 1 would not work, because after you set the Transparency to 1 in the Server, it will override the 0.5 in the Client to 1.

Also setting the Transparency on the Client to 0.5 then firing a RemoteEvent to the Server what will Fire many RemoteEvents to other Players Clients (not yours) what will make your Character for them Transparency 1 would also not work, because players who join new will see your Character.

So we will sending a RemoteEvent to the Server and make the Transparency there to 1, and then firing a RemoteEvent back to you and setting your Character Transparency just for you to 0.5 will work, that will prevent the override from the Server, that should be the best way.

I made a fast Script,

Create a RemoteEvent in ReplicatedStorage and:

Client:

local userInputService = game:GetService("UserInputService")

local remoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")

local player = game:GetService("Players").LocalPlayer

userInputService.InputBegan:Connect(function(inputType)
	
	if inputType.KeyCode == Enum.KeyCode.LeftShift then
		
		remoteEvent:FireServer(true)
		
	end
	
end)

userInputService.InputEnded:Connect(function(inputType)

	if inputType.KeyCode == Enum.KeyCode.LeftShift then
		
		remoteEvent:FireServer(false)

	end

end)

remoteEvent.OnClientEvent:Connect(function(trueOrNil)
	
	if trueOrNil == true then
		
		for index, value in pairs(player.Character:GetDescendants()) do

			if value:IsA("MeshPart") or value:IsA("Decal") then

				value.Transparency = 0.5

			end

		end
		
	elseif trueOrNil == false  then
		
		for index, value in pairs(player.Character:GetDescendants()) do

			if value:IsA("MeshPart") or value:IsA("Decal") then

				value.Transparency = 0

			end

		end
		
	end
	
end)

Server:

local remoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")

local players = game:GetService("Players")

remoteEvent.OnServerEvent:Connect(function(player, trueOrNil)
	
	if trueOrNil == true then		
		
		for index, value in pairs(player.Character:GetDescendants()) do

			if value:IsA("MeshPart") or value:IsA("Decal") then

				value.Transparency = 1

			end

		end
		
		remoteEvent:FireClient(player, trueOrNil)
		
	elseif trueOrNil == false then
		
		for index, value in pairs(player.Character:GetDescendants()) do

			if value:IsA("MeshPart") or value:IsA("Decal") then

				value.Transparency = 0

			end

		end
		
		remoteEvent:FireClient(player, trueOrNil)
		
	end
	
end)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.