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

How would i make a button to where if clicked it rotates the player's orientation?

Im trying to make it so if the player click and hold's a button, it can turn their character depending on if they click and hold the left button or right.

I was thinking of doing something like this :

button = script.Parent
active = false
char = game.Players.LocalPlayer.Character

button.MouseButton1Down:Connet(function()
active = true

if active == true then
turn = char:GetChildren()
while true do
turn.CFrame.fromEulerAnglesXYZ(0, 0, 0) +Vector3.new(1, 1, 1)
end
end
end)

button.MouseButton1Up:Connect(function()
active = false
end)

Im not use to CFraming, so what i wrote may be a bunch of nonsense, but that's an idea i thought on how it would work, but it isn't.

1 answer

✓ Accepted answer

LocalScript in StarterCharacterScripts. Edited for systemis~


local player = game.Players.LocalPlayer
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
local torso = character:WaitForChild("HumanoidRootPart")
local mouse = player:GetMouse()

-- Use UserInputService for user input, not the mouse.
local UserInputService = game:GetService('UserInputService')

UserInputService.InputBegan:Connect(function(input)
	humanoid.AutoRotate = false
	while UserInputService:IsMouseButtonPressed(Enum.UserInputType.MouseButton1) do
		torso.CFrame = CFrame.new(torso.CFrame.p, Vector3.new(mouse.Hit.x, torso.CFrame.y, mouse.Hit.z))
		wait()
	end
	humanoid.AutoRotate = true
end)

2 comments

0

Wow this is amazing, thank's a lot for this. This will help a lot in my game :)

1

I recommend using IsMouseButtonPressed() instead of creating a bool value dedicated to detecting if the mousebutton is held.

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