I have a simple running animation controller, everything works fine on my own screen, but on other people’s screen, the animations never stop even when it has stopped on my client.
How to reproduce: (Replace with own animation Ids)
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
-- Create a new animation instance for running
local newRunAnimation = Instance.new("Animation")
local playRun -- This will hold the AnimationTrack
-- Function to update the AnimationId based on player role
local function updateAnimationId()
local previousAnimationId = newRunAnimation.AnimationId -- Store current AnimationId
-- Determine the new AnimationId based on player role
if player:FindFirstChildOfClass("ObjectValue") == nil then
newRunAnimation.AnimationId = "rbxassetid://180426354" -- Default animation
elseif player:FindFirstChild("test") then
newRunAnimation.AnimationId = "rbxassetid://115846971274296" -- Police run animation
elseif player:FindFirstChild("test2") then
newRunAnimation.AnimationId = "rbxassetid://96621188017208" -- Fireman run animation
else
return -- Exit if no valid role is found
end
-- Reload the animation only if the AnimationId has changed
if newRunAnimation.AnimationId ~= previousAnimationId then
if playRun then
print("stopping")
playRun:Stop() -- Stop the old animation if it's playing
end
playRun = humanoid:LoadAnimation(newRunAnimation) -- Reload with new AnimationId
end
end
-- Call updateAnimationId once to initialize AnimationId
updateAnimationId()
-- Continuously check player movement and role to play/stop the animation
RunService.Heartbeat:Connect(function()
updateAnimationId() -- Update the animation ID based on role if necessary
-- Check if the player is moving
if humanoid.MoveDirection.Magnitude > 0.1 and (not playRun or not playRun.IsPlaying) then
print("starting")
playRun:Play()
elseif humanoid.MoveDirection.Magnitude <= 0.1 and playRun and playRun.IsPlaying then
print("stopping")
playRun:Stop()
end
end)
Next, create parts and insert the script (change tagName) to change the ObjectValue of the player (to change animations) on hit:
-- Define the tag name
local tagName = "test"
-- Function to add the tag to the player
local function onTouch(hit)
-- Check if the object that touched the part is a player
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
if player:FindFirstChildOfClass("ObjectValue") then
local tagToDelete = player:FindFirstChildOfClass("ObjectValue")
tagToDelete:Destroy()
end
-- Check if the player already has the tag
if not player:FindFirstChild(tagName) then
-- Create the tag if it doesn't exist
local tag = Instance.new("ObjectValue")
tag.Name = tagName
tag.Value = player -- Set the value to the player itself
tag.Parent = player
print(player.Name .. " has been given the " .. tagName .. " tag.")
end
end
end
-- Connect the onTouch function to the part's Touched event
script.Parent.Touched:Connect(onTouch)
I believe this is a roblox bug, since the script should work. Could anyone explain why this is?