Hello, I am trying to code a chest vendor that opens when a player clicks it but if they walk away it closes, everything works perfectly except for the animation I am trying to have reverse itself when the player is 15 studs away.
Is there a better method to determine when a player is a certain distance away to resume the animation into a closing position or should I re-work the animation to open then close in the same animation instead of reversing it?
local ac = v.AnimationController
local anim
anim = ac:LoadAnimation(script.WepOpen)
v.WepButton.ClickDetector.MouseClick:Connect(function(plr)
--[[local hum = plr.Parent:FindFirstChild("Humanoid")
if not hum then return end
local plr = game.Players:GetPlayerFromCharacter(hum.Parent)
if not plr then return end]]
local kfc
kfc = anim.KeyframeReached:connect(function(kf) -- Animations
if kf == "Open" then
anim:AdjustSpeed(0)
local ch = plr.Character
local lowerTorso = ch:FindFirstChild("LowerTorso")
if (lowerTorso.Position-v.WepButton.Position).magnitude > 15 then
anim:AdjustSpeed(-1)
end
end
end)
anim:Play()