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)
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)
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
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})
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.