Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
oSyM8V3N 429 Moderation Voter
6 years ago

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

Log in to vote
1
Answered by
Azarth 3141 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

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)
0
Wow this is amazing, thank's a lot for this. This will help a lot in my game :) oSyM8V3N 429 — 6y
1
I recommend using IsMouseButtonPressed() instead of creating a bool value dedicated to detecting if the mousebutton is held. systack 123 — 6y
Ad

Answer this question