Help with playing an animation when a ProximityPrompt is used

Hi, I’m making a ProximityPrompt that places you on a specific position an orientation when used, and it plays an animation on you too.

The problem is when more than 1 player uses it. Everything works fine with the “usePrompt” (the prompt that gives you the position and animation), but when the “backPrompt” (the prompt that stops the animation) is used, the animation stops for everyone who is having the animation too (they are still on “usePrompt” mode, so they still see the “backPrompt”).

Here is the current script:

workspace.Proxim.usePrompt.Triggered:Connect(function(player)
	local animation = script:WaitForChild('Animation')
	local humanoid = player.Character:WaitForChild('Humanoid')
	local anim = humanoid:LoadAnimation(animation)
	anim:Play()
	player.Character.HumanoidRootPart.Position = workspace.tpspyglass.Position
     player.Character.HumanoidRootPart.Orientation = workspace.tpspyglass.Orientation
	
workspace.Proxim.backPrompt.Triggered:Connect(function(player)
		anim:Stop()
	end)
	end)

Here is a Gyazo Gif that shows how it works: https://gyazo.com/8c65434f143b48c02e7594d603b9b346

And here is another Gif that shows the error: https://gyazo.com/0da9b9f7491e364e2e7a47b93b3f3440

Can someone help me with this? What do I have to add/change in the script? Thank you!

1 Like

Is this a local script?
30char

Nope, It is a normal script inside the ProximityPrompt, as shown on this image:

image

It has to be a local script, so that the animation plays and stops for the players locally,

Edit: Oh and place the local script in StarterPlayerScripts

It doesnt work, it breaks the script when only 1 player uses it too, because I have to define “anim” on both scripts, and I guess that duplicates the animation or something. It executes the “:LoadAnimation()” on both scripts

oh yeah , sorry that message was a mistake, you’re gonna have to make the entire script local and place it in StarterPlayerScripts

Tried that and the script breaks completely :sweat_smile: