Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to make a part spin around a player on touch?

Hello! I know this isnt a request site and I am not trying to request anything. I only want to know: How do I make a part (my shields) move around a player that's touching a part? I have tried googling, doing it myself etc but I cant find anything on how to make parts spin around the player, and I also don't know how I would make the touched function send the player variable to the server so it would make only the touching player have the shields. If you guys think this is a request please comment notifying me and ill remove it imideatly! Sorry if this question is badly formulated or asked, I don't ask things like this very often

EDIT: Purpose is spawn protection, when the player touches a non collide brick that's invisible a touched event will be fired and make the player have the shields spinning around it until it stops being in the spawn (brick)

4 comments

0

For clarification: i dont need to know how to make the player be spawn protected but how to make the player have the shields around it

0

If I'm not mistaken, you want the player to have shields that orbit him or to have them stay in place while circling him?

0

Kinda, if we take the solar system as an example, then the player is the sun and the shields (3 shields) are 3 planests. I want the shields to spin around the player in the same "orbit" (not in different directions or closer/further away from the player like the planets) so the shields are going to spin around the player while the player is touching the safezone part

0

If you think its easier to communicate via discord u can add me: LOL!#1728, that way u get a ping when i reply and its easier to communicate

1 answer

This is where we use maths.

If you aren't familiar with parametric equations then this might fly over your head.

We know that x = rcos? and y = rsin?. Which is coincidentally the equation for a circle. If we use a loop to set a part's position to this, relative to the player's torso, or head we will achieve circular orbit.

I'm not going to go step-by-step so I hope you can reverse-engineer this to fit your own needs.

local function moveCircle(theta, radius)
	local Head = Player.Character:WaitForChild("Head")
	local positionX = radius * math.cos(theta)
	local positionZ = radius * math.sin(theta)
		
	script.Parent.CFrame = CFrame.new(Head.Position.X + positionX, Head.Position.Y, Head.Position.Z + positionZ)
end
	
while wait() do
	local theta = tick()
	moveCircle(theta, 10)
end

If you know the parametric equations for a shape, you can make that orbit.

3 comments

0

Thanks for your reply!, would you mind explaining how i would make that trigger for ONLY 1 player on a brick touch? Thanks in advance!

0

Also: i Tried using ur script to see what would happen and know how i would go frmo reverse enginering it frmo there but it gives an error on the Player.chaacter:WaitForChild() line, i do not know how to a) get the player b) get the player to do that when its touching instead of making all players get the effect

0

Use the touchedPart that is returned from the touched connection (Touched:Connect(TouchedPart)) and navigate to the character directly, usually it's TouchedPart.Parent.

This discussion is preserved as it was. New answers, comments, and votes are closed.