Forcefield tween problem

Hi, I am trying to make a forcefield that spins around the player and sometimes moves up and down.
But I have a problem with the forcefield. It wont let the player move normaly and also its spinning the wrong way and I cant anchor it because then the player wont be able to move. If the forcefield is activated (from a item) then it creates a weld between the middlepart and the HumanoidRootPart of the character in the player. Heres a picture how the forcefield looks like:

The middlepart holds all the circles and the shields with welds.

So if I activate the forcefield it wont let me move normaly and it spins completly wrong. I am using a tween and I with that I am trying to spin it around the player.

Here´s the part of the script for the tween:

for i,v in pairs(ForceField:GetChildren()) do
				if v:IsA("MeshPart") then
				
					local Tweeninfo = TweenInfo.new(5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, -1, true)
					local Goal = {Orientation = v.CFrame * Vector3.new(math.rad(360), math.rad(0), math.rad(0))}
						
					local Tween = TweenService:Create(v,Tweeninfo,Goal)
					Tween:Play()
				end
			end

Does anybody know how to fix that?

Instead of welding the stuff to the player make it so it keeps moving to the Position of the player.
Maybe that will work?
Something like this:

while wait() do
     for i, v in pairs(game.Workspace.forcefield:GetChildren()) do
           if v:IsA("MeshPart") then
               v.Position = player.Position -- put the player who drank the thing's position here
           end
     end
end

I’m not sure if this will work as I am kind of new to scripting.

1 Like

The player can move normaly now but it kinda makes it shaky because of the wait() command and it would fall of the world after some time. Also I cant remove the wait() command because it would crash the game instantly. I think a weld would be better.

Instead of using while, use

game:GetService("RunService").RenderStepped:Connect(function()
	
end)
1 Like

You can anchor the meshes now as they are no longer welded. That should take care of the falling down the map and with the “Shakiness” you can make it lerp to the player’s position that would make it seem more natural.
Though if you think welding is better then that’s up to you.
And yes do the thing SnoopDoge is saying.

1 Like

This will only work as localscript tho, so you would have to make a remote event that would move it to the player position, so everyone could see it moving with player, if it wont work with localscript.
(Replying to my previous reply)

1 Like

its fixed now but the forcefield is still moving up

What do you mean moving up?
Like literally going up?
Could you provide a recording

ignore the “a few hours later” text that from annother script in the game

Sorry man, I don’t know how to fix that. Good luck though.

1 Like

I would prefer using task.wait().

Try rotating it on the Y axis, not the X axis. It looks like it’s rotating on the X.

like this? local Goal = {Orientation = v.CFrame.Y * Vector3.new(math.rad(360))}

but its still doing the same problem but it got slower

Maybe try

local Goals = {CFrame = CFrame.new(MainPart.Position) * CFrame.fromOrientation(0, math.rad(360), 0)}

(Main part is referring to the central part of the forcefield)

1 Like

Its fixed now. But it stays still now it wont spin somehow

Maybe try

while task.wait() do MainPart.CFrame = CFrame.new(MainPart.Position) * CFrame.fromOrientation(0, math.rad(Main part.Orientation + Vector3.new(0,2,0), 0)} end

It’s a lil janky but it should work.

The reason for this is because rotating an object 360 degrees brings it back where it started so in the tweens side of things its like it doesnt need to rotate, I recommend you instead make an infinite loop that adds small increments to the rotation.

local RunService = game:GetService('RunService')

RunService.RenderStepped:Connect(function() 
      MainPart.CFrame = CFrame.new(MainPart.Position) * CFrame.Angles(math.rad(1),0,0) 
end)
You can either increase or decrease the increment to make it more smooth

math.rad(MainPart.Orientation + Vector3.new(0,2,0), 0) is underlined with orange I dont know how to fix that to be honest it looks too complicated to me xd

it says argument count mismatch

how do I activate the runservice so it can go from the localscript to the serverscript?