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

BodyGyro CFrame not updating?

I edited my fireball script and everything is much better now than before. The only problem is that when I set the ButtonDown value to true, the print function works perfectly, but the BodyGyro CFrame to update in the for i loop doesn't change. Can anyone fix this?

The server script. The local script just invokes a RemoteFunction deletes the BodyGyro and BodyPosition.

game.ReplicatedStorage.BlazeInvoke.OnServerInvoke = function(plr, MouseHit)
	
	print("Working!")
	--Variables--
	local char = plr.Character
	print(char)
	local RootPart = char:WaitForChild("HumanoidRootPart")
	local animation = script:WaitForChild("Animation")
	local hum = char.Humanoid
	animTrack = hum:LoadAnimation(animation)
	local hitdebounce = false
	script.ButtonDown.Value = true
	circle = game.ReplicatedStorage.MagicItems.MagicCircles.BlazeMagic.BlazeCircle:Clone()
		circle.Size = Vector3.new(10,10,10)
		circle.Parent = game.Workspace.CustomDebris
		circle.Anchored = false
		circle.CanCollide = false
		circle.Transparency = 1
		circle.CFrame = char.HumanoidRootPart.CFrame * CFrame.new(1.5,0,-2)
	
	local Weld = Instance.new("Weld")
		Weld.Parent = circle
		Weld.Part0 = circle
		Weld.Part1 = RootPart
		Weld.C0 = CFrame.new(1.5,0,-2)
	
	bp = Instance.new("BodyPosition")
		bp.Parent = char.Torso
		bp.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
		bp.Position = char.Torso.Position
		bp.Name = "TorsoPosition"
		bg = Instance.new("BodyGyro")
		bg.D = 100
		bg.Parent = char.Torso
		bg.MaxTorque = Vector3.new(math.huge,math.huge,math.huge)
		bg.CFrame = CFrame.new(char.Torso.Position, MouseHit)
		bg.Name = "MouseGyro"
		
		if script.ButtonDown.Value == true then
			
			for i = 1, 110 do
				
				bg.CFrame = CFrame.new(char.Torso.Position, MouseHit)
				print("Changing BG CFrame")
				
				wait(2)
			end
			
			
			
			
			
		end
	
	
	
	
end

2 comments

0

try setting the P or Power property of the BodyGyro

0

in the for i loop or before it? if so what would that do? is it not strong enough to work? because it works without the for i loop. the character smoothly faces the mouse. i just want it to follow it like that for a certain amount of time

1 answer

This is happening because the value of MouseHit remains the same within the loop; it will always point towards the same MouseHit position that was sent when the remote was first invoked. While you could solve this by repeatedly sending the mouse hit position to give the server the updated position, this may take up unnecessary remote bandwidth.

However, as the player automatically has Network Ownership over their character, any movement to the character by a local script will automatically replicate to the server. This means that you can create and rotate the BodyGyro from a local script without using remote events, and everyone will still see the movement. So to solve this you are able to move the BodyGyro from your local script, using the up-to-date Mouse.Hit.Position.

Hope this helps!

2 comments

0

so you know how my RemoteFunction invoke is in a local script? could i create the bodygyro from there, and everyone will still see the movement?

0

Yep pretty much

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