Can someone please help me

Been waiting days. but no one answered my old post so made a new one. This script stops running after the client invoke thing.

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local HumanoidRootPart = Humanoid.Parent:WaitForChild("HumanoidRootPart")
local RemoteFunction = script.Parent.RemoteFunction

local RP = game:FindService("ReplicatedStorage")
local Event = RP.InAir
-----------Animations---------------------

--//Ani 1 (Defualt)//--
local Animation = script.DefualtSwing
local AnimationTrack = Humanoid:LoadAnimation(Animation)
--//Ani 2 (T-Pose)//--
local Animation2 = script.TPoseSwing
local Animation2Track = Humanoid:LoadAnimation(Animation2)
--// Ani 3 (UpsideDown)//--
local Animation3 = script.UpsideDown
local Animation3Track = Humanoid:LoadAnimation(Animation3)
-------------------------------------------

local RopeAmount = Player:WaitForChild("NumberOfHooks"):WaitForChild("Amount")

local EventDB = false

Event:FireServer()

game:GetService("RunService").Stepped:Connect(function()
RemoteFunction.OnClientInvoke = function(player,data,TPoseEquipped,TPoseOwned,GoldenHookEquipped,GoldenHookOwned) --Wont run past here
		if Humanoid:GetState() == Enum.HumanoidStateType.Freefall then
          if RopeAmount.Value == 1 then
			    local char = Player.Character
				
				if data == nil then
				
					if TPoseEquipped.Value == false then
						AnimationTrack:Play()
						AnimationTrack.Looped = true
					end
						
				  else
					
					if TPoseEquipped.Value == true then
						Animation2Track:Play()
						Animation2Track.Looped = true
					elseif TPoseEquipped.Value == false then
							AnimationTrack:Play()
							AnimationTrack.Looped = true
				   end	
				end
				
		    elseif RopeAmount.Value == 0 then
				
				if data == nil then
					
					if TPoseEquipped.Value == false then
					    AnimationTrack:Stop()	
					end
					
					else 
					
					if TPoseEquipped.Value == true then
						Animation2Track:Stop()
					elseif TPoseEquipped.Value == false then
						AnimationTrack:Stop()
					end
				end	
				
			end
		end
     end			
wait(.5)
end)
1 Like

You shouldn’t use RemoteFunctions for Server > Client communication, you should instead be using RemoteEvents.

Your function also doesn’t return anything, which would most likely stop any code below.

And, just a question, why are animations being initiated by the server?

The script is a client script.

I know its a client script.

I’m saying you’re using the wrong kind of server to client communication.

Re-read the post.

With the question, I was mainly asking why the server sends through if the animation can be played or not?

The client should be able to find the values, so why bother sending them through the server? Its extra data you could just not send.

2 Likes

I used a remote event but it exhausted the script because it fires every second.

Hello, I am not 100% sure If this fixes the issue but you should separate the OnClientInvoke function from the Stepped event.

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local HumanoidRootPart = Humanoid.Parent:WaitForChild("HumanoidRootPart")
local RemoteFunction = script.Parent.RemoteFunction

local RP = game:FindService("ReplicatedStorage")
local Event = RP.InAir
-----------Animations---------------------

--//Ani 1 (Defualt)//--
local Animation = script.DefualtSwing
local AnimationTrack = Humanoid:LoadAnimation(Animation)
--//Ani 2 (T-Pose)//--
local Animation2 = script.TPoseSwing
local Animation2Track = Humanoid:LoadAnimation(Animation2)
--// Ani 3 (UpsideDown)//--
local Animation3 = script.UpsideDown
local Animation3Track = Humanoid:LoadAnimation(Animation3)
-------------------------------------------

local RopeAmount = Player:WaitForChild("NumberOfHooks"):WaitForChild("Amount")

local EventDB = false

Event:FireServer()

RemoteFunction.OnClientInvoke = function(player,data,TPoseEquipped,TPoseOwned,GoldenHookEquipped,GoldenHookOwned)
    if Humanoid:GetState() == Enum.HumanoidStateType.Freefall then
        if RopeAmount.Value == 1 then
            local char = Player.Character
            
            if data == nil then
            
                if TPoseEquipped.Value == false then
                    AnimationTrack:Play()
                    AnimationTrack.Looped = true
                end
                    
            else
                
                if TPoseEquipped.Value == true then
                    Animation2Track:Play()
                    Animation2Track.Looped = true
                elseif TPoseEquipped.Value == false then
                        AnimationTrack:Play()
                        AnimationTrack.Looped = true
                end 
            end
            
        elseif RopeAmount.Value == 0 then
            
            if data == nil then
                
                if TPoseEquipped.Value == false then
                    AnimationTrack:Stop()    
                end
                
            else 
                
                if TPoseEquipped.Value == true then
                    Animation2Track:Stop()
                elseif TPoseEquipped.Value == false then
                    AnimationTrack:Stop()
                end
            end 
        end
    end
end

game:GetService("RunService").Stepped:Connect(function()
    -- Your other code that needs to run every frame
end)

This should fix the issue you were having and allow the OnClientInvoke function to work correctly.

Still nothing, this is the server script:

the print doesnt even go through. I need to make it so it constantly knows when the player is in the air, and I think it only does it once, before the player even loads.

local Players = game:GetService("Players")
local RP = game:FindService("ReplicatedStorage")
local Event = RP.InAir

local RemoteFunction = script.Parent.RemoteFunction


Event.OnServerEvent:Connect(function(player)
	
	print("3")
	local DataManager = require(game:GetService("ReplicatedStorage").DataManager)
	local data = DataManager:Get(player)

	local TPoseEquipped = data.TPoseEquipped
	local TPoseOwned = data.TPoseOwned
	local GoldenHookEquipped = data.GoldenHookEquipped
	local GoldenHookOwned = data.GoldenHookOwned

	RemoteFunction:InvokeClient(data,TPoseEquipped,TPoseOwned,GoldenHookEquipped,GoldenHookOwned)
	
end)
Event.OnServerEvent:Connect(function(player)
    print("3")
    local DataManager = require(game:GetService("ReplicatedStorage").DataManager)
    local data = DataManager:Get(player)

    local TPoseEquipped = data.TPoseEquipped
    local TPoseOwned = data.TPoseOwned
    local GoldenHookEquipped = data.GoldenHookEquipped
    local GoldenHookOwned = data.GoldenHookOwned

    RemoteFunction:InvokeClient(player, data, TPoseEquipped, TPoseOwned, GoldenHookEquipped, GoldenHookOwned)
end)

I dont really see a difference between mine and yours, but I still tested it and it does not work.

I made this:

And it seems like the event is not being fired at all.

while true do
if	Humanoid:GetState() == Enum.HumanoidStateType.Freefall then
	print("1")
	Event:FireServer()
	wait(.5)
	end	
	wait(.5)
end