Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Animation doesn't load when client fires sever?

When my client fires a Remote Event, the server doesn't return any error. When I do fire the event, the first animation never seems to load. There's no indacation in my script that says straight out of the bloom, "Hey, this is an error." Take a look at the server script.

local PunchEvent = game.ReplicatedStorage:WaitForChild('punch')
local Cooldown = 0.8

local PunchData = {}
local Cooldowns = {}

local function PlaySound(ID,Parent)
    local Sound = Instance.new("Sound")
    Sound.SoundId = "rbxassetid://"..ID
	Sound.PlayOnRemove = true
    Sound.Parent = Parent
    Sound:Destroy()
end

function Make(Character)
		local CantRegen = Instance.new("IntValue")
		CantRegen.Name = "CantRegen"
		CantRegen.Parent = Character
		game.Debris:AddItem(CantRegen, 1)
end

PunchEvent.OnServerEvent:Connect(function(Player)
	
	if Cooldowns[Player] then -- player has used cooldowns before
		if Cooldowns[Player] >= tick() - Cooldown then -- player has not completed cooldown
			return -- return code so code below doesn't execute
		end
	end
	
	Cooldowns[Player] = tick() -- set so player can not use punch event for cooldown seconds
	
	local Data = Player:WaitForChild('Data')
	local Stamina = Data:WaitForChild('Stamina')
	
	if Stamina.Value < 11 then
		return
	else
		Stamina.Value = Stamina.Value - 10	-- take 10 stamina away
	end
	
	local Character = Player.Character or Player.CharacterAdded:Wait() -- get player character, if it doesn't exist wait for it
	
	Make(Character)
	
	local Humanoid = Character:WaitForChild("Humanoid")
	local Animator = Humanoid:WaitForChild("Animator")
	
	if PunchData[Character] == nil then -- if there is no data for this character
		PunchData[Character] = { -- set it for the first time
			["LeftPunch"] = Animator:LoadAnimation(game:GetService("ReplicatedStorage"):WaitForChild("Left")),
			["RightPunch"] = Animator:LoadAnimation(game:GetService("ReplicatedStorage"):WaitForChild("Right")), -- doesnt load
			["LastPunch"] = "LeftPunch",
			["CanPunch"] = true
		}
	end
	
	local SecondaryDataTable = PunchData[Character]
	
	local RightHand = Character.RightHand
	local LeftHand = Character.LeftHand

	local CurrentConnection = nil
	local CurrentAnimationTrack = nil
	
	if SecondaryDataTable.LastPunch == "LeftPunch" then
		SecondaryDataTable.CanPunch = false
		SecondaryDataTable.LastPunch = "RightPunch"
		
		PlaySound(711753382, Character.RightHand)
		CurrentAnimationTrack = SecondaryDataTable.RightPunch
		
		CurrentConnection = Character.RightHand.Touched:Connect(function(Hit)
			local Humanoid = Hit.Parent:FindFirstChildOfClass("Humanoid")
			if Humanoid then
				Humanoid:TakeDamage(12)
				PlaySound(367499850, RightHand)
				CurrentConnection:Disconnect()
			end
		end)
		
		
	elseif SecondaryDataTable.LastPunch == "RightPunch" then
		SecondaryDataTable.CanPunch = false
		SecondaryDataTable.LastPunch = "LeftPunch"
		
		PlaySound(711753382, LeftHand)
		CurrentAnimationTrack = SecondaryDataTable.LeftPunch
		
		CurrentConnection = Character.LeftHand.Touched:Connect(function(Hit)
			local Humanoid = Hit.Parent:FindFirstChildOfClass("Humanoid")
			if Humanoid then
				Humanoid:TakeDamage(12)
				PlaySound(367499850, LeftHand)
				CurrentConnection:Disconnect()
			end
		end)
		
		CurrentAnimationTrack:Play()
		CurrentAnimationTrack.Stopped:Wait()
		if CurrentConnection then CurrentConnection:Disconnect() end
		SecondaryDataTable.CanPunch = true
	end
end)

And here's the client script.

local Players = game:GetService('Players')
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local UserInputService = game:GetService('UserInputService')

local Player = Players.LocalPlayer
local PunchEvent = game.ReplicatedStorage.punch

UserInputService.InputBegan:Connect(function(Key, GameProcessedEvent)
    if not GameProcessedEvent then
        if Key.UserInputType == Enum.UserInputType.MouseButton1 then
            PunchEvent:FireServer()
        end
    end
end)

4 comments

0

You actually don't need a RemoteEvent to play animations, animations are part of player physics, so they replicate. I'd only use the RemoteEvent for dealing damage.

0

So how do I solve my problem?

0

Well I don't think you should be nesting events inside of others, like the Touched events you have. You could make a script, parent under the script, and clone it when the key is pressed from the remote.

0

Seems benefical. But, how does this tie in with the animation problem?

1 answer

function square(iteratorMaxCount,currentNumber)

if currentNumber<iteratorMaxCount then currentNumber = currentNumber+1 return currentNumber, currentNumber*currentNumber end

end

for i,n in square,3,0 do print(i,n) end and nowit is more than enough to add the transfer time in seconds transformed into data

3 comments

2

This has nothing to do with the question.

0

^^

0

yes it does! He just need this to learn !

This discussion is preserved as it was. New answers, comments, and votes are closed.