Crouch system on server

How can I make it visible to other players? I tried using RemoteEvent, but it was difficult for me to synchronize the movements

local TweenService = game:GetService("TweenService")
local Humanoid = game:GetService("Players").LocalPlayer.Character:WaitForChild("Humanoid")
local HumanoidRootPart = game:GetService("Players").LocalPlayer.Character:WaitForChild("HumanoidRootPart")
local plr = game:GetService("Players").LocalPlayer

local CrouchAnimation = script.Animation
local CrouchTrack = Humanoid:LoadAnimation(CrouchAnimation)
local SitCrouchTrack = Humanoid:LoadAnimation(script.SitAnimation)

local CameraInfo = TweenInfo.new(
	0.75,
	Enum.EasingStyle.Quint,
	Enum.EasingDirection.Out,
	0,
	false,
	0
)

local CrouchGoal = {CameraOffset = Vector3.new(0, -1.75, 0)}
local UnCrouchGoal = {CameraOffset = Vector3.new(0, 0, 0)}

local CrouchedTween = TweenService:Create(Humanoid, CameraInfo, CrouchGoal)
local UnCrouchedTween = TweenService:Create(Humanoid, CameraInfo, UnCrouchGoal)

local inCrouch = false
local kd = 0

game:GetService("UserInputService").InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.C then
		if kd == 0 then
			if inCrouch == false then
				kd = 1
				inCrouch = true
				CrouchedTween:Play()
				Humanoid.WalkSpeed = 8
				CrouchTrack:Play()

				HumanoidRootPart.CanCollide = false
				wait(0.2)
				kd = 0

			else
				inCrouch = false
				UnCrouchedTween:Play()
				Humanoid.WalkSpeed = 16
				CrouchTrack:Stop()
				SitCrouchTrack:Stop()

				HumanoidRootPart.CanCollide = true
			end
		end
	end
end)

Humanoid.Changed:Connect(function()
	if Humanoid.MoveDirection.Magnitude == 0 and inCrouch == true then
		if CrouchTrack.IsPlaying == true then
			CrouchTrack:Stop()
		end
		if SitCrouchTrack.IsPlaying == false then
			SitCrouchTrack:Play()
		end
	elseif Humanoid.MoveDirection.Magnitude > 0 and inCrouch == true then
		if SitCrouchTrack.IsPlaying == true then
			SitCrouchTrack:Stop()
		end
		if CrouchTrack.IsPlaying == false then
			CrouchTrack:Play()
		end
	end
end)

Animations played through the LocalPlayer’s character on a LocalScript already replicate to other clients and the server.

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