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

Why do the animations fail to load in game server but not studio?

It works in the studio but not in servers... The animations are mine and the local script is in StarterPack/Backpack. Also im using FilteringEnabled

Player = game.Players.LocalPlayer
Mouse = Player:GetMouse()
local charge = 0
debounce = false
local Punchnum = 1
local Blastnum = 1
local BlastAnim = Instance.new("Animation")
local BlastAnim2 = Instance.new("Animation")
local StartingChargingAnim = Instance.new("Animation")
local HoldChargeAnim = Instance.new("Animation")
local PunchAnim = Instance.new("Animation")
local PunchAnim2 = Instance.new("Animation")
local KickAnim = Instance.new("Animation")
StartingChargingAnim.AnimationId = "http://www.roblox.com/Asset?ID=633268286"
HoldChargeAnim.AnimationId = "http://www.roblox.com/Asset?ID=633312531"
BlastAnim.AnimationId = "http://www.roblox.com/Asset?ID=633244897"
BlastAnim2.AnimationId = "http://www.roblox.com/Asset?ID=633247868"
PunchAnim.AnimationId = "http://www.roblox.com/Asset?ID=629944086"
PunchAnim2.AnimationId = "http://www.roblox.com/Asset?ID=629965827"
KickAnim.AnimationId = "http://www.roblox.com/Asset?ID=633423754"

Mouse.KeyDown:connect(function(key)
 if not debounce then
		debounce = true
   if key == "e" then 
	   print("Blast")
	 if Player.PlayerGui.Energy.Value >=5 then
		Player.PlayerGui.Energy.Value =   Player.PlayerGui.Energy.Value  - 5
	     if Blastnum == 1 then
		  local animTrack = Player.Character.Humanoid:LoadAnimation(BlastAnim)
          animTrack:Play()
          Blastnum = 2
          wait(0.4)
         elseif Blastnum == 2 then
		  local animTrack = Player.Character.Humanoid:LoadAnimation(BlastAnim2)
          animTrack:Play()
          Blastnum = 1
          wait(0.4)
	     end
	 end
   elseif key == "q" then
	   print("Punch")
	    if Punchnum == 1 then
		 local animTrack = Player.Character.Humanoid:LoadAnimation(PunchAnim)
         animTrack:Play()
         Punchnum = 2
         wait(0.5)
        elseif Punchnum == 2 then
		 local animTrack = Player.Character.Humanoid:LoadAnimation(PunchAnim2)
         animTrack:Play()
         Punchnum = 3
         wait(0.5)
        elseif Punchnum == 3 then
		 local animTrack = Player.Character.Humanoid:LoadAnimation(KickAnim)
         animTrack:Play()
         Punchnum = 1
         wait(0.3)
	    end
	elseif key == "0" then
	   print("Charging")
	   local animTrack = Player.Character.Humanoid:LoadAnimation(StartingChargingAnim)
	   animTrack:Play()
	   charge = 1
	
	   Player.Character.Humanoid.JumpPower = 0
	   Player.Character.Humanoid.WalkSpeed = 0
	   wait(0.3)
	   Charge()
     end
  debounce = false
 end
end)

Mouse.KeyUp:connect(function(key)
	if key == "0" then
		charge = 0
		Player.Character.Humanoid.JumpPower = 50
	   Player.Character.Humanoid.WalkSpeed = 16
	end
end)

function Charge()
 while charge == 1 do
  local animTrack = Player.Character.Humanoid:LoadAnimation(HoldChargeAnim)
	  animTrack:Play()
	 if Player.PlayerGui.Energy.Value < 100 then
     Player.PlayerGui.Energy.Value = Player.PlayerGui.Energy.Value +1
	     elseif Player.PlayerGui.Energy.Value ==100 then
		end
  wait(0.05)
 end
end

1 answer

Use WaitForChild() What WaitForChild does it is waits until the item in question is completely loaded into the game before attempting to access it. In studio, it is already loaded, so no error occurs. But in game, it needs to load it from the servers, which causes this error to occur

2 comments

0

Where do i put it tho

0

anywhere you are trying to load a instance

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