I'm trying to get my "idle" animation to only be activated if the player has not moved for 40 consecutive seconds. I've only managed to get the animation to play after 20 seconds if the player isn't moving by the 20th second, but this isn't really what I want:
-- This local script doesn't work correctly. It's meant to be an AFK animation, -- -- as in when the player has been idle without moving their mouse for 20 seconds, -- -- then the animation will play until the player moves their chacter -- local Player = game.Players.LocalPlayer local Humanoid = Player.Character.Humanoid local mouse = Player:GetMouse() local animate = Instance.new("Animation") animate.Name = "animate" animate.AnimationId = "http://www.roblox.com/Asset?ID=2056648365" debounce = false mouse.Idle:connect(function(Idle) if debounce == true then return end debounce = true wait(9) repeat wait() until Player.Character.HumanoidRootPart.Velocity == Vector3.new(0,0,0) == true do print 'idle start' wait(1) if Player.Character.HumanoidRootPart.Velocity == Vector3.new(0,0,0) == false then return elseif Player.Character.HumanoidRootPart.Velocity == Vector3.new(0,0,0) == true then print 'Idle' script.Parent.Folder.IdleWallEvent:FireServer(Player) end local playAnimate = Humanoid:LoadAnimation(animate) playAnimate:Play() repeat wait() until Player.Character.HumanoidRootPart.Velocity == Vector3.new(1,1,1) == false do return end if Player.Character.HumanoidRootPart.Velocity == Vector3.new(1,1,1) then playAnimate:Stop() wait(0.01) print 'Idle Deactivated' end debounce = false end end)
I then decided to use a script to insert my animation into the player, in hopes that I could make the animations play in an order. However, this was unsuccessful as well. I was trying to make it to where my custom animation wouldn't play unless the player had been idle for 20 seconds using weighting:
local Player = game.Players.LocalPlayer local mouse = Player:GetMouse() local Idle = Instance.new("Animation") Idle.Name = "Idle" Idle.AnimationId = "http://www.roblox.com/Asset?ID=2056648365" Idle.Parent = Player.Character.Animate.idle local Weight = Instance.new("NumberValue") Weight.Name = "Weight" Weight.Parent = Player.Character.Animate.idle.Idle Weight.Value = 2 local OtherWeight = Player.Character.Animate.idle.Animation1.Weight OtherWeight.Value = 4 local OtherOtherWeight = Player.Character.Animate.idle.Animation2.Weight OtherOtherWeight.Value = 3 repeat wait(0.1) until Player.Character.LowerTorso.Orientation == Player.Character.HumanoidRootPart.Orientation + Vector3.new(10.38,0,0) do print 'idle start' wait(1) if Player.Character.LowerTorso.Orientation == Player.Character.HumanoidRootPart.Orientation + Vector3.new(10.38,0,0) == false then return elseif Player.Character.LowerTorso.Orientation == Player.Character.HumanoidRootPart.Orientation + Vector3.new(10.38,0,0) == true then print 'Idle' wait(0.01) script.Parent.Folder.IdleWallEvent:FireServer(Player) end end
And here's the function:
local Wall local success, err = pcall(function() Wall = game:GetService("InsertService"):LoadAsset(2096107433) end) if success then Wall.Parent = workspace print("successfully inserted Wall") else warn("unable to insert Wall because " .. err) end local Player = game.Players.LocalPlayer local wall = game.Workspace.Model.SmoothBlockModel wall.CanCollide = false wall.Anchored = true wall.Transparency = 0 wait(0.1) wall.Orientation = Player.Character.HumanoidRootPart.Orientation wall.Position = Player.Character.LowerTorso.Position + Vector3.new(-0.051, 5.548, 2.177) wall.Transparency = 0 local yes = Instance.new("Part") yes.Name = "yes" yes.Parent = game.Workspace yes.CanCollide = false yes.Anchored = true yes.Position = Player.Character.LowerTorso.Position yes.Transparency = 0 repeat wait(0.5) until Player.Character.LowerTorso.CFrame == yes.CFrame == false do Wall:Destroy() print 'Wall Destroyed' yes:Destroy() print 'Almost Done' end end script.Parent.Folder.IdleWallEvent.OnServerEvent:connect(wallcreate)
As you can see I am a little stumped and so I was hoping somebody on here could help me.
https://wiki.roblox.com/index.php?title=API:Class/Player/Idled
Player.Idled:Connect(function(idledTime) code end)
Edit code: Note: Sometimes it won't work, so I added some stuff.
wait() local plr = game:GetService("Players").LocalPlayer local c = plr.Character or plr.CharacterAdded:Wait() repeat wait() until c ~= nil local torso = c:WaitForChild("Torso") local oldPos, idled = nil, false torso.Changed:Connect(function(diff) if diff == "Position then if torso.Position == oldPos then idled = true end end end) spawn(function() while idled do code wait(1) end end) while wait(1) do oldPos = torso.Position end