Need help changing outline transparency

Hi. I’m making a crouching system that makes the player’s outline no longer visible once they crouch.
I’m running into an issue though. Whenever a player crouches, it changes everybody else’s outline to be invisible as well even if they aren’t crouching. Here’s my code.

Local Script

HideEvent.OnClientEvent:Connect(function(receivedMessage: string)
	if receivedMessage == "Crouched" then
		CrouchSound:Play()
	end
end)

Mouse.KeyDown:Connect(function(Key)
	
	if Key == 'c' then
		
	
		crouching.Value = true
		CrouchAnimation:Play()
		HideEvent:FireServer("Crouched")

Server Script

HideEvent.OnServerEvent:Connect(function(player: Player, request: string)
	if typeof(request) ~= "string" then
		return
	end

	if typeof(player) ~= "Instance" then
		return
	end

	if request == "Crouched" then

		Tween({FillTransparency = 1})
		Tween({OutlineTransparency = 1})
		HideEvent:FireClient(player, "Crouched")

			end
		end)

Any help would be greatly appreciated. Thanks.

1 Like

I would do something a whole lot easier which is using attributes. You can assign them on server and detect when they’re changed on client. Here is a quick example.

-- server
game.Players.PlayerAdded:Connect(function(Player)
  Player.CharacterAdded:Connect(function(Character)
    Character:SetAttribute('Crouching', false)
  end)
end)

HideEvent.OnServerEvent:Connect(function(Player, Argument)
  if not Player or not Player.Character then return end

  if  Player.Character:GetAttribute('Crouching') ~= Argument then
    Player.Character:SetAttribute('Crouching', Argument)
      for _, Player in pairs(Players:GetPlayers()) do
          Player:FireClient(Player.Character, Argument)
      end
  end
end)

-- Client
local Crouching = false

game.UserInputService.InputBegan:Connect(function(Input, Ignore)
  if Input == Enum.KeyCode.C then
    Crouching = not Crouching
    HideEvent:FireServer(Crouching)
  end
end)

HideEvent.OnClientEvent:Connect(function(Character, Argument)
  if Character == nil then return end

   if Argument == true then
      Tween(Character, {OutlineTransparency = 0}) -- Make work on any Character.
    elseif Argument == false then
      Tween(Character, {OutlineTransparency = 1}) -- Make work on any Character.
  end
end)
1 Like

There’s some other ways of doing this but this is probably one of the easiest. Plus I am feeling extremely lazy right now.

Your Tween function doesn’t seem to require you to specify the player whose outline transparency you want to tween, so I would imagine that calling Tween makes the change for every player and you will have to edit it to allow for you to specify an individual player to tween.

If I’m wrong then I can take another look if you post the code for Tween

Sure.

local function Tween(g)
	TweenService:Create(char:WaitForChild("Highlight"),TweenInfo.new(0.1),g):Play()
end

--If I were to change the transparency--
	Tween({FillTransparency = 1})
	Tween({OutlineTransparency = 1})

Since its being called in a server script how is char being defined?

image

I used

local char = script.Parent.Parent.Parent

I might be wrong but I’m pretty sure server-side Scripts don’t work in StarterCharacterScripts. Place it in ServerScriptService, and get the Character from the Player parameter passed across the RemoteEvent.

4 Likes

It worked. Thanks for your help!

1 Like

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