LogService MessageOut doesnt work ingame. What do i replace it with?

I want to replace the message outs that i used to play animations at the right moment because they do not work.
Here is the server and client scripts

Server:

local UpdateAmmoEvent = game.ReplicatedStorage:WaitForChild("UpdateAmmoCountGlock17")

local ammoLeft = 17
local reloading = false

local function reload(manual)
	if reloading then return end
	if ammoLeft == 17 then return end
	reloading = true
	ReloadSound:Play()
	if manual and ammoLeft == 0 then
		print("ReloadGlock17Empty")
	else
		print("ReloadGlock17NotEmpty")
	end
	wait(2.3)
	ammoLeft = 17
	UpdateAmmoEvent:FireAllClients(ammoLeft)
	reloading = false
end

function PlayFireSound()
	local NewSound = FireSound:Clone()
	local MuzzleFlash = script.Parent.Handle.MuzzleFlash.MuzzleEffect 
	NewSound.Parent = Handle
	NewSound:Play()
	MuzzleFlash:Emit(20)
	if ammoLeft == 0  then
		print("GunFiredGlock17Last")
	else
		print("GunFiredGlock17")
	end
	Debris:AddItem(NewSound, NewSound.TimeLength)
end

function Fire(direction)
	if Tool.Parent:IsA("Backpack") then return end

	local directionalCF = CFrame.new(Vector3.new(), direction)

	if ammoLeft > 0 and not reloading then
		local direction = (directionalCF * CFrame.fromOrientation(0, 0, RNG:NextNumber(0, TAU)) * CFrame.fromOrientation(math.rad(RNG:NextNumber(MIN_BULLET_SPREAD_ANGLE, MAX_BULLET_SPREAD_ANGLE)), 0, 0)).LookVector

		local humanoidRootPart = Tool.Parent:WaitForChild("HumanoidRootPart", 1)
		local myMovementSpeed = humanoidRootPart.Velocity
		local modifiedBulletSpeed = (direction * BULLET_SPEED)

		if PIERCE_DEMO then
			CastBehavior.CanPierceFunction = CanRayPierce
		end

		local simBullet = Caster:Fire(FirePointObject.WorldPosition, direction, modifiedBulletSpeed, CastBehavior)
		ammoLeft -= 1

		UpdateAmmoEvent:FireAllClients(ammoLeft)
		PlayFireSound()
	else
		reload(false)  -- Automatically triggered reload
	end
end

function ManualReload()
	if ammoLeft == 1 then
		reload(false)  -- Trigger automatic reload animation
	else
		reload(true)  -- Manually triggered reload
	end
end

Client:

local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local LogService = game:GetService("LogService")
local RunService = game:GetService("RunService")

local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

local function setupViewModel()
	-- Destroy existing viewmodel if it exists
	if workspace.CurrentCamera:FindFirstChild("ViewModelGlock17") then
		workspace.CurrentCamera.ViewModelGlock17:Destroy()
	end

	-- Clone the viewmodel from ReplicatedStorage
	local viewmodel = ReplicatedStorage:WaitForChild("ViewModelGlock17"):Clone()
	viewmodel.Parent = workspace.CurrentCamera

	-- Get the Animator
	local animator = viewmodel:WaitForChild("Humanoid"):WaitForChild("Animator")

	-- Load the animations
	local Ranimation = Instance.new("Animation")
	Ranimation.AnimationId = "rbxassetid://72523018738433" -- Replace with your animation ID
	local RanimationTrack = animator:LoadAnimation(Ranimation)
	local REanimation = Instance.new("Animation")
	REanimation.AnimationId = "rbxassetid://97988611711973" -- Replace with your animation ID
	local REanimationTrack = animator:LoadAnimation(REanimation)
	local REEmptyAnimation = Instance.new("Animation")
	REEmptyAnimation.AnimationId = "rbxassetid://120156932108231" -- Replace with your animation ID for empty reload
	local REEmptyAnimationTrack = animator:LoadAnimation(REEmptyAnimation)
	local RanimationL = Instance.new("Animation")
	RanimationL.AnimationId = "rbxassetid://86438961102865" -- Replace with your animation ID for last shot
	local RanimationLTrack = animator:LoadAnimation(RanimationL)
	local WalkAnimation = Instance.new("Animation")
	WalkAnimation.AnimationId = "rbxassetid://111477854942676" -- Replace with your animation ID
	local WalkAnimationTrack = animator:LoadAnimation(WalkAnimation)
	WalkAnimationTrack.Looped = true
	-- Function to stop all playing animations
	local function stopAllAnimations()
		for _, track in ipairs(animator:GetPlayingAnimationTracks()) do
			track:Stop()
		end
	end
	
	local camera = workspace.CurrentCamera
	
	local function moveCameraUp()
		local currentCFrame = camera.CFrame
		local newCFrame = currentCFrame * CFrame.Angles(math.rad(1), 0, 0)
		camera.CFrame = newCFrame
	end
	
	-- Function to play the animations
	local function RecoilAnimation()
		stopAllAnimations()
		RanimationTrack:Play()
	end
	local function ReloadAnimation()
		stopAllAnimations()
		REanimationTrack.Priority = Enum.AnimationPriority.Action4
		REanimationTrack:Play()
	end
	local function ReloadEmptyAnimation()
		stopAllAnimations()
		REEmptyAnimationTrack:Play()
	end
	local function LastShotAnimation()
		stopAllAnimations()
		RanimationLTrack:Play()
	end

	-- Lock position at the end of the last shot animation
	RanimationLTrack.Stopped:Connect(function()
		local lastFrameCFrame = viewmodel.PrimaryPart.CFrame -- Assuming PrimaryPart is set
		viewmodel:SetPrimaryPartCFrame(lastFrameCFrame)
	end)

	-- Connect the log messages to the animations
	LogService.MessageOut:Connect(function(message, messageType)
		if message == "GunFiredGlock17" then
				moveCameraUp()
				RecoilAnimation()
			end
		if message == "GunFiredGlock17Last" then
				moveCameraUp()
				LastShotAnimation()
			end
		if message == "ReloadGlock17NotEmpty" then
			ReloadAnimation()
		elseif message == "ReloadGlock17Empty" then
			ReloadEmptyAnimation()
		end
	end)

	-- Function to handle walking animation
	local function updateWalkingAnimation()
		if character.Humanoid.MoveDirection.Magnitude > 0 then
			if not WalkAnimationTrack.IsPlaying then
				WalkAnimationTrack:Play()
			end
		else
			if WalkAnimationTrack.IsPlaying then
				WalkAnimationTrack:Stop()
			end
		end
	end

	-- Connect the walking animation update to the RenderStepped event
	RunService.RenderStepped:Connect(updateWalkingAnimation)
end


-- Function to handle tool equipped
local function onToolEquipped(tool)
	if tool.Name == "Glock 17" then
		setupViewModel()
	end
end

-- Connect the tool equipped event
player.Character.ChildAdded:Connect(function(child)
	if child:IsA("Tool") then
		onToolEquipped(child)
	end
end)

-- Handle tool replacement
player.Character.ChildRemoved:Connect(function(child)
	if child:IsA("Tool") and child.Name == "Glock 17" then
		setupViewModel()
	end
end)

Why are you using LogService to begin with? You should be triggering the animations using game events or direct function calls rather than relying on log messages.

1 Like

This is pretty strange to me too

It says right at the top of the documentation that it shouldn’t be used for any important game logic

1 Like

How come you’re just not using remote events…?

1 Like

It just seemed the easiest to me. The other ones seemed confusing or i didnt know how to use them

You should learn how to use remote events, they’re pretty important and not that complicated. You can find the documentation here, and a youtube tutorial here.

1 Like

watch some tutorials on RemoteEvents/RemoteFunctions, and read the docs for them to get a bit of a better idea.

They’re pretty straightforward after you use them once or twice.

2 Likes

Oh and i heard that they cant be fired on server scripts and i use a server script of the fire, reload and audio functions. Will this work?

1 Like

They can be fired from the server or the client

Edit: A serverscript cannot fire an event to another serverscript and the client can’t fire events to itself, it can only be one-way from either direction:
Client->Server or Server->Client

That would be what BindableEvents are for.

3 Likes

Use a global variable that references an event. That way you don’t have to reference the event repeatedly. Other than for this use case I don’t recommend using globals

1 Like

is the firing an event in server this? Glock17Fire:FireAllClients()

1 Like

Yeah, if you want to trigger a sound/animation to play for all the clients to keep some of the load off of the server, you’d use that once the server picks up that someone is firing a weapon from an event fired by the client.

1 Like

You can also fire to a specific player if you just want something to happen for them.

Event:FireClient(player, yourArg, yourOtherArg, ...)
1 Like

is this recieving of the event good?

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local FireNotEmpty = ReplicatedStorage["Glock 17 RE"]:WaitForChild("Glock17Fire")

FireNotEmpty.OnClientEvent:Connect(function()
	moveCameraUp()
	RecoilAnimation()
end)
1 Like

ooo it works finally some good solution

1 Like

Yep. Try it out with a few things and you’ll start getting the hang of how it works.

Something to note also, is that the function in the event connection can use parameters sent over from the event

-- SERVER --
Event:FireClient(player, true, 10)

--------
-- CLIENT --
Event.OnClientEvent:Connect(function(arg1, arg2)
    if arg1 == true then
        Value += arg2
    else
        print("FAILED!")
    end
end)

1 Like

That will be useful. Thx for help!

1 Like

np, just make sure you mark one of these dudes’ replies as a solution so people don’t keep spamming replies lol

hey, i still have one issue. so in the client (on the original post) theres a function called moveCameraUp and when i reequip the tool (destroy the vmodel and put it back to the camera) it just starts turning more and more times at the same time depending on how much i reequip it. so the recoil is being bigger than i want to. do u know why is that?

1 Like