How do I make a part rotate?

I’m trying to make a script where when the player enters the chatbar, a bubblechat pops up and rotates above their head–to illustrate/show that the character is typing on their keyboard. Currently my problem is that I am trying to make the part rotate:

BubblePart.Orientation = BubblePart.Orientation + Vector3.new(0,1,0)

but the part is not rotating after it spawns above my player’s head. How can I fix my problem?

local Player = game.Players.LocalPlayer -- This is a vriabale for the player
local Mouse = Player:GetMouse() --This is gonna get the player's mouse
local BubblePart = Instance.new('Part', game.ServerStorage)  --//[[For some reason this script doesn't like local BubblePart variable definiton here specifically. Nothign works]]

game:GetService("UserInputService").InputBegan:connect(function(key,chatting) -- We made a function for whenever you press a key, it fires
	warn(chatting)
	if chatting then	
		if not Player.Character.Head:FindFirstChild('ChatPart') then
			local BubblePart = Instance.new('Part', Player.Character.Head)
			BubblePart.Name = 'ChatPart'
			BubblePart.CanCollide = false
			--BubblePart.Anchored = true
			BubblePart.CFrame = Player.Character.Head.CFrame * CFrame.new(0,2,0)
			local Weld = Instance.new("WeldConstraint", Player.Character.Head)
			Weld.Part0 = Player.Character.Head
			Weld.Part1 = BubblePart

		end

		print('C')
	end

	while wait() do
		print('waiting')
		if not chatting then
			print('not  chatting now.')
			Player.Character.Head:FindFirstChild('ChatPart'):destroy()
			print('part destroyed')
			break
		end
		BubblePart.Orientation = BubblePart.Orientation + Vector3.new(0,1,0)
	end

end)

BubblePart.Orientation = BubblePart.Orientation * Vector3.new(0,1,0)

i tested your script earlier, first there are a few things that i improved that i suggest using in the future

  • parenting a part after all of its properties are set will increase performance slightly, if there are no properties to be set, then that is my only exception for using the 2nd argument in Instance.new()
  • runservice.renderstepped is quicker allowing smoother transitions especially when used on the client
  • :connect() is deprecated, the new version is :Connect()
  • weld’s have cframe values that are manually set through c0, and c1 which are offset cframes so you would want to use that instead of weldconstraints to make a rotation type movement

here’s the script, re@ me if something doesn’t work.

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local BubblePart = Instance.new('Part', game.ServerStorage)
local UserInputService = game:GetService("UserInputService")
local ChatBar = Player.PlayerGui.Chat.Frame.ChatBarParentFrame.Frame.BoxFrame.Frame.ChatBar
local RunService = game:GetService("RunService")

UserInputService.InputBegan:Connect(function(KeyCode, GameProcessedEvent)
	if GameProcessedEvent then
		if not Player.Character.Head:FindFirstChild('ChatPart') then
			local BubblePart = Instance.new("Part")
			BubblePart.Name = "ChatPart"
			BubblePart.CanCollide = false
			BubblePart.Massless = true
			BubblePart.Parent = Player.Character.Head
			local Weld = Instance.new("Weld")
			Weld.Name = "BubbleWeld"
			Weld.Part0 = Player.Character.Head
			Weld.Part1 = BubblePart
			Weld.C1 = CFrame.new(0, -2.5, 0)
			Weld.Parent = Player.Character.Head
			local FocusLost = false
			ChatBar.FocusLost:Connect(function()
				FocusLost = true
				coroutine.yield()
			end)
			while RunService.RenderStepped:Wait() do
				if FocusLost then
					if BubblePart:IsDescendantOf(game) then
						BubblePart:Destroy()
					end
					if Weld:IsDescendantOf(game) then
						Weld:Destroy()
					end
					break
				else
					Weld.C1 *= CFrame.Angles(0, math.rad(0.5), 0)
				end
			end
		end
	end
end)
1 Like

I’ve made changes based off of your suggestions, seems the part is rotating but I cannot for some reason figure out why it won’t stop rotating after I finish typing. What’s supposed to happen is player presses the ‘/’ key to start typing. Then, when player starts typing, the part is supposed to appear above the player’s head and rotate while the player is typing. Once the player finishes typing and presses the Enter key, which sends their message in the chat, the part should go away or disappear from above their head.

local Player = game.Players.LocalPlayer -- This is a vriabale for the player
local Mouse = Player:GetMouse() --This is gonna get the player's mouse
local BubblePart = Instance.new('Part', game.ServerStorage)  --//[[For some reason this script doesn't like local BubblePart variable definiton here specifically. Nothign works]]

game:GetService("UserInputService").InputBegan:Connect(function(key,chatting) -- We made a function for whenever you press a key, it fires
	warn(chatting)
	if chatting then	
			if not Player.Character.Head:FindFirstChild('ChatPart') then
				local BubblePart = Instance.new('Part', Player.Character.Head)
				BubblePart.Name = 'ChatPart'
				BubblePart.CanCollide = false
				--BubblePart.Anchored = true
				BubblePart.CFrame = Player.Character.Head.CFrame * CFrame.new(0,2,0)
				--local Weld = Instance.new("WeldConstraint", Player.Character.Head)
				--Weld.Part0 = Player.Character.Head
				--Weld.Part1 = BubblePart
				local Weld = Instance.new("Weld")
				Weld.Part0 = Player.Character.Head
				Weld.Part1 = BubblePart
				Weld.C1 = CFrame.new(0, -2.5, 0)
				Weld.Parent = Player.Character.Head
			
				while wait() do
					Weld.C1 *= CFrame.Angles(0, math.rad(3.5), 0)
					print('waiting')
						if not chatting then
							print('not  chatting now.')
							Player.Character.Head:FindFirstChild('ChatPart'):destroy()
							print('part destroyed')
							break
						end
				end
			end
			print('C')
	end
end)

BubblePart.Orientation = BubblePart.Orientation * Vector3.new(0,1,0)

Can we see your chatting variable and function to check if chatting

What I posted above is the entire script.

Alright just making sure but I might be blind but I don’t see where you change the value of your “chatting”

A little change of order

local Player = game:GetService("Players").LocalPlayer
local Mouse = Player:GetMouse()

Head = (Player.Character or Player.CharacterAdded:Wait()):WaitForChild("Head")

local BubblePart = Instance.new('Part') 
BubblePart.Name = 'ChatPart'
BubblePart.CanCollide = false
BubblePart.CFrame = Head.CFrame * CFrame.new(0,2,0)

local Weld = Instance.new("Weld", BubblePart)
Weld.Part0 = Head
Weld.Part1 = BubblePart
Weld.C1 = CFrame.new(0, -2.5, 0)

game:GetService("UserInputService").InputBegan:Connect(function(key,chatting)
	warn(chatting)
	if chatting then   BubblePart.Parent = Head
	else			   BubblePart.Parent = nil
	end
end)

while wait() do
	if BubblePart.Parent ~= Head then			continue				end
	Weld.C1 *= CFrame.Angles(0, math.rad(3.5), 0)
end