How would I script a candy collection system?

I want to have a piece of candy that rotates 360 repeatedly and have a proximity prompt. When the player holds the prompt until it’s complete I want to have a particle effect happen and the candy disappears. I also want the collected candy to be a leaderstat thing.

For this assuming the item is anchored and doesn’t move, CFrame method is most reliable (Nothing can stop and interrupt it). From CFrame math article CFrame Math Operations. For an un welded model I recommend using the :PivotTo() function.

local door = game.Workspace.Door
	door.CFrame = door.CFrame * CFrame.Angles(0, math.rad(1)*dt*60, 0)

Use prompt triggered to detect when it’s complete ProximityPrompt.Triggered.

To make it happen once use particle emitter ParticleEmitter:Emit. If continuos enable ParticleEmitter.Enabled.

Locate the player leaderstat, (possible as proximity prompt gives player instance) and add it.

Adding onto this you could also achieve the rotation effect with the use of TweenService as well. Using a tween is also more smooth if your looking for that and doesn’t require all the CFrame math

Unfortunately, I didn’t recommend tween service because of a bug it has when rotating 360 as it goes to the shortest path from start to goal.

To counteract this problem the solution is pretty lengthy (see below) as you gotta tween in sections, However I guess it still works and you can modify tweeninfo to make it more funky.

I never knew there was issues with not being able to a 360 tween. I never encountered the issue myself though thanks for stating it.

Ok so I tested it out and the coin seems to turning vertically instead of horizontaly.