Hello! My animations and all the code worked before, now I change all the local script code into one new localscript ( local script location was changed) and the animations no play, could someone help me see why that happens? what’s wrong with my code, please.
LOCALSCRIPT:
-- Input Services
local UIS = game:GetService('UserInputService')
local Player = game.Players.LocalPlayer
local Character = Player.Character
-- Declared
local intvalue = Instance.new("IntValue")
intvalue.Name = "Stamina"
local frame = script.Parent
local ydefault = 1
-- INPUTS AND STAMINA DECREASES SYSTEM
function RunAnimCall(rcall)
if rcall then -- If started sprinting
print("Started sprinting")
intvalue.Value -= 15
else -- Stopped sprinting
print("Stopped sprinting")
end
end
UIS.InputBegan:connect(function(input)--When a player has pressed LeftShift it will play the animation and it will set the normal walking speed (16) to 35.
if input.KeyCode == Enum.KeyCode.LeftShift then
Character.Humanoid.WalkSpeed = 35
local Anim = Instance.new('Animation')
Anim.AnimationId = 'rbxassetid://913376220'
PlayAnim = Character.Humanoid:LoadAnimation(Anim)
PlayAnim:Play()
RunAnimCall(true) -- Calls RunAnimCall with rcall as true.
end
end)
UIS.InputEnded:connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
Character.Humanoid.WalkSpeed = 16
PlayAnim:Stop()
RunAnimCall(false) -- Calls RunAnimCall with rcall as false.
end
end)
-- STAMINA FUNCTIONS
-- Regen Stamina
intvalue.Changed:Connect(function()
frame.Size = UDim2.new(intvalue.Value/100,0,ydefault, 0)
end)
intvalue.Value = 1
repeat
if intvalue.Value >= 0 then
for i = 0, 100, 20 do
intvalue.Value = i
print("Your stamina percentage is: " .. intvalue.Value)
wait(2)
end
print("Your stamina is complete")
intvalue.Value = 1
end
until intvalue.Value == 150
-- PLAYING ANIMS
-- LIGHT AND HEAVY HITS ARE THERE
-- Declared
local player = game.Players.LocalPlayer
repeat wait() until player.Character.Humanoid
local humanoid = player.Character.Humanoid
local stopAnim = player.Character
-- Defense animation
local defanim = Instance.new("Animation")
defanim.AnimationId = "rbxassetid://6233839018" --defend id 6233839018 --boxpose: 6234302765
-- Light hit animation
local light_hit_anim = Instance.new("Animation")
light_hit_anim.AnimationId = "rbxassetid://6234034921"
-- Concentrate hit animation
local con_hit_anim = Instance.new("Animation")
con_hit_anim.AnimationId = "rbxassetid://6233901250"
-- BoxPose
local boxpose = Instance.new("Animation")
boxpose.AnimationId = "rbxassetid://6234302765"
-- Input system
UserInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local c = false
game.Workspace.Tool.Handle.Touched:Connect(function() --tool touched
-- Defense anim F key
UserInputService.InputBegan:Connect(function(input, gameProccesedEvent)
if input.KeyCode == Enum.KeyCode.F then
print("Playing defense animation! done.")
local playAnim = humanoid:LoadAnimation(defanim)
playAnim:Play()
script.DefAnim:FireServer()
end
end)
-- Light attack anim with the left mouse click:
local Debounce = false
UserInputService.InputBegan:Connect(function(input, gameProccesedEvent)
if not Debounce and input.UserInputType == Enum.UserInputType.MouseButton1 then
Debounce = true
print("Light attack activated")
local playAnim = humanoid:LoadAnimation(light_hit_anim)
playAnim:Play()
script.LightHitAnim:FireServer()
wait(0.5)
Debounce = false
c = true
if c == true then
print("Inside box pose")
local playBoxPose = humanoid:LoadAnimation(boxpose)
playBoxPose:Play()
wait(5)
end
end
end)
-- Concentrate attack anim with the right mouse click:
local Debounce = false
UserInputService.InputBegan:Connect(function(input, gameProccesedEvent)
if not Debounce and input.UserInputType == Enum.UserInputType.MouseButton2 then
Debounce = true
print("Heavy attack activated")
local playAnim = humanoid:LoadAnimation(con_hit_anim)
playAnim:Play()
script.BigHitAnim:FireServer()
wait(5)
Debounce = false
end
end) -- End of tool touched
end)
SERVERSCRIPT:
-- SERVER CONECCTION
-- Defense anim connected to server
game.StarterGui.Game.Background.StaminaBar.StamSystemAnims.DefAnim.OnServerEvent:Connect(function()
print("Connected to defense anim.")
end)
-- Light hit anim connected to server
game.StarterGui.Game.Background.StaminaBar.StamSystemAnims.LightHitAnim.OnServerEvent:Connect(function(plr)
print("Connected to light hit anim.")
-- Damage functions
local AttackDist = 10 --If a player is further than this value, they won't be damaged.
for i,v in pairs(game.Players:GetChildren()) do --Loops through all players.
if v.Character ~= nil and plr.Character ~= nil and v ~= plr then --Checks if there's a character
local pRoot = plr.Character:FindFirstChild("HumanoidRootPart")
local vRoot = v.Character:FindFirstChild("HumanoidRootPart")
if pRoot and vRoot and (plr.Character.HumanoidRootPart.Position - v.Character.HumanoidRootPart.Position).Magnitude < AttackDist then --Checks if the Root parts exist and if the player is in range.
local Hum = v.Character:FindFirstChild("Humanoid")
if Hum and Hum.Health > 0 then --Checks if player is alive.
Hum.Health = Hum.Health - 10 --Change "100" to the damage the player should take.
end
--Stuff that happens when a player is in range.
end
end
end
end)
-- Concentrate big hit anim connected to server
game.StarterGui.Game.Background.StaminaBar.StamSystemAnims.BigHitAnim.OnServerEvent:Connect(function(plr)
print("Connected to concentrate hit anim.")
-- Damage functions
local AttackDist = 10 --If a player is further than this value, they won't be damaged.
for i,v in pairs(game.Players:GetChildren()) do --Loops through all players.
if v.Character ~= nil and plr.Character ~= nil and v ~= plr then --Checks if there's a character
local pRoot = plr.Character:FindFirstChild("HumanoidRootPart")
local vRoot = v.Character:FindFirstChild("HumanoidRootPart")
if pRoot and vRoot and (plr.Character.HumanoidRootPart.Position - v.Character.HumanoidRootPart.Position).Magnitude < AttackDist then --Checks if the Root parts exist and if the player is in range.
local Hum = v.Character:FindFirstChild("Humanoid")
if Hum and Hum.Health > 0 then --Checks if player is alive.
Hum.Health = Hum.Health - 25 --Change "100" to the damage the player should take.
end
--Stuff that happens when a player is in range.
end
end
end
end)
PLEASE I DON’T KNOW WHAT IS WRONG WITH MY CODE ![]()
