Yeah, it’s a mess. I’ll rewrite this tommorow.
You have to update the character and humanoid local variables. If you don’t, the variables will reference the old humanoid and character instances that were destroyed when you died.
local player = game.Players.LocalPlayer
local character = player.Character
local humanoid = character.Humanoid
player:GetPropertyChangedSignal('Character'):Connect(function()
character = player.Character or player.CharacterAdded:Wait()
humanoid = character.Humanoid
end
just so you know, i recommend not converting the local script into a normal script since animations from the client are already replicated into the server by automatic, there are no reason to convert it into a normal script and unnecessarily if you’re going to fire the server
i don’t recommend doing this as it also clears the default walking animations temporarily until the animations restart
If I need to update, where should I put that block of code? when I put this, I get an error:
Humanoid = Character.Humanoid
Humanoid = Character:WaitForChild("Humanoid")
Or use:
Humanoid = Character:FindFirstChildOfClass("Humanoid")
if Humanoid then
--Code
end
Converting it to a normal script has no difference. Using a RemoteEvent to gain a certain stat is really bad because exploiters could easily fire the RemoteEvent as much as they want to.
You have to use a signal. Try putting it in a spot that you know would be set before the humanoid dies.
The code I gave you previously was pseudocode, and I would recommend you use :WaitForChild
This is the code, works perfectly but when i die or reset i have an error:
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local tool = script.Parent
local Animator = Humanoid:FindFirstChild("Animator")
local Anim = Instance.new("Animation")
Anim.AnimationId = "rbxassetid://6350259222"
local AnimationTrack = Animator:LoadAnimation(Anim)
local Anim2 = Instance.new("Animation")
Anim2.AnimationId = "rbxassetid://6364334315"
local AnimationTrack2 = Animator:LoadAnimation(Anim2)
local RS = game:GetService("ReplicatedStorage")
local Strength = RS.RemoteEvents.Strength
local db = false
--Animation
tool.Equipped:Connect(function()
AnimationTrack:Play()
AnimationTrack.Priority = Enum.AnimationPriority.Idle
Humanoid.UseJumpPower = true
Humanoid.WalkSpeed = 0
Humanoid.JumpPower = 0
end)
tool.Activated:Connect(function()
if db == false then
db = true
AnimationTrack2:Play()
AnimationTrack2.Priority = Enum.AnimationPriority.Action
Strength:FireServer()
wait(2)
db = false
end
end)
tool.Unequipped:Connect(function()
AnimationTrack:Stop()
AnimationTrack2:Stop()
Humanoid.UseJumpPower = true
Humanoid.WalkSpeed = 16
Humanoid.JumpPower = 50
end)
This code doesn’t help. Show me where you defined your humanoid.
ok, this is the code I got recently, but the problem is that the player gets up out of nowhere and the animations do not play as they should and also, the animation 2 of the activated event does not work or is not seen:
local Tool = script.Parent
local function Equipped()
local Character = Tool.Parent
if Character and Character:FindFirstChildOfClass("Humanoid") and Character.Parent == game:GetService("Workspace") then
local Humanoid = Character.Humanoid
Humanoid.JumpHeight = 0
Humanoid.WalkSpeed = 0
local Animator = Humanoid.Animator
local Animation = Instance.new("Animation")
Animation.AnimationId = "rbxassetid://6350259222" --Animation 1
local AnimationTrack = Humanoid:LoadAnimation(Animation)
AnimationTrack:Play()
AnimationTrack.Priority = Enum.AnimationPriority.Idle
end
end
Tool.Equipped:Connect(Equipped)
local Debounce = true
local Animator = nil
local Humanoid = nil
local function Activated()
if Debounce == true then
Debounce = false
local Character = Tool.Parent
if Character and Character:FindFirstChildOfClass("Humanoid") and Character.Parent == game:GetService("Workspace") then
Humanoid = Character.Humanoid
Animator = Humanoid.Animator
local Animation = Instance.new("Animation")
Animation.AnimationId = "rbxassetid://6364334315" --Animation 2
local AnimationTrack = Humanoid:LoadAnimation(Animation)
AnimationTrack:Play()
AnimationTrack.Priority = Enum.AnimationPriority.Action
end
local Players = game:GetService("Players")
local Player = Players:GetPlayerFromCharacter(Character)
Player.leaderstats.Strength.Value += 1
wait(2)
Debounce = true
end
end
Tool.Activated:Connect(Activated)
local function Unequipped()
if Humanoid then
Humanoid.JumpHeight = 7.2
Humanoid.WalkSpeed = 16
end
if Animator then
local PlayingAnimationTracks = Animator:GetPlayingAnimationTracks()
for _, PlayingAnimationTrack in pairs(PlayingAnimationTracks) do
PlayingAnimationTrack:Stop()
end
end
end
Tool.Unequipped:Connect(Unequipped)
This is in a server script.