Hello, I’m looking to execute an animation when the player uses a ProximityPrompt, I also want the player to be moved to where the animation has ended, any idea how I could do this?
I attempted this script and got no result.
Hello, I’m looking to execute an animation when the player uses a ProximityPrompt, I also want the player to be moved to where the animation has ended, any idea how I could do this?
I attempted this script and got no result.
This will need to be a server Script that’s a child of your script.Parent
:
local TARGET = Vector3.new(0, 3, -24)
local instance = script.Parent
local prompt = instance.ProximityPrompt
local animation = instance.Animation
local debounce = {}
local function onTriggered(player)
if debounce[player] then return end
debounce[player] = true
local humanoid = player.Character.Humanoid
local track = humanoid.Animator:LoadAnimation(animation)
track:Play()
track.Ended:Wait()
humanoid:MoveTo(TARGET)
humanoid.MoveToFinished:Wait()
debounce[player] = nil
end
prompt.Triggered:Connect(onTriggered)
Edit: @HERRKNOCHEN I added a per-player debounce now to prevent reactivation of the prompt while the code is running
Hey there, thank you so much for your help. I’m having a hard time figuring out what you meant. Would it be okay if you add comments for what I need to change to make this work for me? I’ve attached the names of all my variables.
The TARGET
found in line 1 is the target position you’d like the character to stop walking to. I’ll add comments to add more info like you suggested:
local TARGET = Vector3.new(0, 3, -24) -- The target Vector3 where the character stops working (safe to change but must be a Vector3 value)
local animationTrigger = script.Parent -- The AnimationTrigger Part
local prompt = animationTrigger.ProximityPrompt -- The ProximityPrompt
local animation = animationTrigger.Animation -- The Animation
local debounce = {} -- The per-player debounce table. It's per-player else the debounce would prevent other players from activating the prompt
local function onTriggered(player)
if debounce[player] then return end -- If debounce is active return from function
debounce[player] = true -- Activate the debounce
local humanoid = player.Character.Humanoid
local track = humanoid.Animator:LoadAnimation(animation)
track:Play()
track.Ended:Wait() -- Waits for the AnimationTrack to finish playing (Won't work if the animation loops though)
humanoid:MoveTo(TARGET) -- Makes the character walk to the target position
humanoid.MoveToFinished:Wait() -- Waits for the character to finish walking to the destination
debounce[player] = nil -- Deactivates the debounce
end
prompt.Triggered:Connect(onTriggered)
Edit: @HERRKNOCHEN Also I’m unsure as to whether this script is the LogVault
script or the script inside of ServerScriptService, but for this server Script to work it needs to be inside of the AnimationTrigger Part
I managed to get this working now, however when the animation has finished and the player is supposed to walk to where they need to go, the player model goes back to where the animation starts.
robloxapp-20240118-1116499.wmv (1.8 MB)
That’s odd. It’s not happening to me when I test the script I gave you in a new blank baseplate though, here’s the place file where I’m testing: PromptAnimationExample.rbxl (54.8 KB)
look closely…
Animatior is misspelled
I tried it on here with my animation, I think it has something to do with my animation rather than your code, because when the animation is executed it goes back to the starting position and then goes to the target.
robloxapp-20240118-1158075.wmv (731.9 KB)
It does seem to be an issue with the animation unfortunately, I’ll see if I can find information on making animations for climbing over objects and will edit this reply if I do find something useful for you
Edit: I tried my best to find information that would be useful for you, but unfortunately there doesn’t seem to be anything that would be relevant for your problem. I would suggest researching about Inverse Kinematics since you might be able to use it in order to guarantee that the character correctly climbs over the obstacle
Inverse Kinematics, HingeConstraint - Roblox Scripting Tutorial
Edit2: @HERRKNOCHEN I would also like to mention that there’s a chance you need to use pathfinding in order to make the character jump over the obstacle
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.