This is happening because the player’s character doesn’t load with the player. You can use player.CharacterAdded for this.
But, you shouldn’t be creating a new event every single time a player joins your game! This will create multiple duplicate events that will create a huge memory leak over time. Instead, try something like this:
RunningEvent.OnServerEvent:Connect(function(player)
if player.Character and player.Character:FindFirstChild("Humanoid") then
Run:Play()
player.Character.Humanoid.WalkSpeed = 25
end
end)
Well first of all I suggest to handle the animations + WalkSpeed client-sidedly mainly.
This would probably fix your struggles.
So just replace RunningEvent:FireServer() with
Run:Play()
humanoid.WalkSpeed = 25
and NotRunningEvent:FireServer() with
Run:Stop()
humanoid.WalkSpeed = 16
and put the follow variables at the start:
local animator = character:WaitForChild("Humanoid"):WaitForChild("Animator")
local Run = animator:LoadAnimation(animation) -- Humanoid:LoadAnimation() is deprecated
but I suggest to put this script in StarterCharacterScripts instead of StarterPlayerScripts or whatever.
local Animator = script.Parent:WaitForChild("Humanoid"):WaitForChild("Animator") -- Fix this path if needed, I am assuming that script.Parent is the character
local animation = -- define this
local Run = animator:LoadAnimation(animation)
Wherever you send a message to the 1st event RunningEvent:FireServer(), you replace this with
Run:Play()
humanoid.WalkSpeed = 25
Then for the 2nd event NotRunningEvent:FireServer() you replace this with: