Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do i fix my script?When i press W twice it doesnt run.

Asked by 4 years ago
local Trcanje = Instance.new('Animation') 
local Player = game.Players.LocalPlayer
local Character = Player.Character
local TickJeste = tick()
 Trcanje.AnimationId = 'rbxassetid://4766569612'
 PlayTrcanje = Character.Humanoid:LoadAnimation(Trcanje)

game:GetService("UserInputService").InputBegan:connect(function(input,gameprocesed)
 if input.KeyCode == Enum.KeyCode.W then
  for i = 1,16 do
local TickDa = tick()
local TimePassed = TickDa - TickJeste
if TimePassed <= 1 then
  wait()
   game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed = game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed + 1.5
    PlayTrcanje:Play()
   end
  end
 end
end)


game:GetService("UserInputService").InputEnded:connect(function(input,gameprocesed)
 if input.KeyCode == Enum.KeyCode.W then
  for i = 1,16 do
    local TimePassed = TickJeste
    if TimePassed <= 1 then
  wait()
   game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed = game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed - 1.5
    PlayTrcanje:Stop()
   end
  end
 end
end)

game.Players.LocalPlayer.Character:WaitForChild("Humanoid").Died:connect(function()
 game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16
 script.Disabled = true
end)

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

you can't Humanoid:LoadAnimation() in a LocalScript. you need to do that on the server first which will create an Animator object in the humanoid.. once there's an animator object, then you can do Humanoid:LoadAnimation() in a LocalScript

Edit:

in a server script do this:

local track = Humanoid:LoadAnimation(animation_object) <-- this will create a roblox object called Animator, once that's done then you can do track:Play() and that will work fine b/c an animator object has been created..

0
How can i do that can u show me an example?? TheAkiSa 7 — 4y
0
i just edited it User#23252 26 — 4y
Ad

Answer this question