I have been trying to work on a script that will force a user to have a certain walk/run animation if they are a certain rank in a group.
Here’s the code I’ve created:
local Players = game:GetService("Players")
local function onCharacterAdded(character)
Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function()
if plr:GetRankInGroup(5030945) >= 13 then
local humanoid = character:WaitForChild("Humanoid")
for _, playingTracks in pairs(humanoid:GetPlayingAnimationTracks()) do
playingTracks:Stop(0)
end
local animateScript = character:WaitForChild("Animate")
animateScript.run.RunAnim.AnimationId = "rbxassetid://6300166393" -- Run
animateScript.walk.WalkAnim.AnimationId = "rbxassetid://6300166393" -- Walk
else
print("User is not required rank")
end
end)
end)
end
local function onPlayerAdded(player)
player.CharacterAppearanceLoaded:Connect(onCharacterAdded)
end
There are no errors in the output section, nor does it print “User is not required rank.” However, it doesn’t give the animation to me.
Originally, I was using this script where it gave the animation to everybody, and it was working just fine:
local Players = game:GetService("Players")
local function onCharacterAdded(character)
local humanoid = character:WaitForChild("Humanoid")
for _, playingTracks in pairs(humanoid:GetPlayingAnimationTracks()) do
playingTracks:Stop(0)
end
local animateScript = character:WaitForChild("Animate")
animateScript.run.RunAnim.AnimationId = "rbxassetid://6300166393" -- Run
animateScript.walk.WalkAnim.AnimationId = "rbxassetid://6300166393" -- Walk
end
local function onPlayerAdded(player)
player.CharacterAppearanceLoaded:Connect(onCharacterAdded)
end
Players.PlayerAdded:Connect(onPlayerAdded)
When I edited it to work with certain group ranks, then it stopped working.
why are you firing character added then player added first of all
you should be doing character added then getting the player name and searching for the player in players instead or just doing it on player added after character added
@S0MBRX was what I was going to say, I noticed you tried waiting for the character to load before the player did
local function onCharacterAdded(character)
plr.CharacterAdded:Connect(function()
if plr:GetRankInGroup(5030945) >= 13 then
local humanoid = character:WaitForChild("Humanoid")
for _, playingTracks in pairs(humanoid:GetPlayingAnimationTracks()) do
playingTracks:Stop(0)
end
local animateScript = character:WaitForChild("Animate")
animateScript.run.RunAnim.AnimationId = "rbxassetid://6300166393" -- Run
animateScript.walk.WalkAnim.AnimationId = "rbxassetid://6300166393" -- Walk
else
print("User is not required rank")
end
end)
end
local function onPlayerAdded(player)
player.CharacterAppearanceLoaded:Connect(onCharacterAdded)
end
Players.PlayerAdded:Connect(onPlayerAdded)
Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function()
if plr:GetRankInGroup(5030945) >= 13 then
local function onCharacterAdded(character)
(This isn’t the whole script, of course, just the beginning)
Your functions were kind of unnecessary, so I’ve changed your script a little. Let me know if it works
local Players = game:GetService('Players')
Players.PlayerAdded:Connect(function(player)
if player:GetRankInGroup(5030945) >= 13 then
player.CharacterAdded:Connect(function(character)
local humanoid = character:WaitForChild("Humanoid")
for _, playingTracks in pairs(humanoid:GetPlayingAnimationTracks()) do
playingTracks:Stop(0)
end
local animateScript = character:WaitForChild("Animate")
animateScript.run.RunAnim.AnimationId = "rbxassetid://6300166393" -- Run
animateScript.walk.WalkAnim.AnimationId = "rbxassetid://6300166393" -- Walk
end)
else
print("User is not required rank")
end
end