I trying to make a skill system so I make a first skill that can hold press and aim at anywhere while you use it your roblox character will face to your mouse position and get freezed but the problem is when I aim at the floor my roblox character keep shaking and when I release skill button it just gonna fling my character
here is some of my code (I’m new for scripting so my script probably look messy sorry for that, you can comment and give me any information about scripting I will take your advice Thank you!)
local plr = game.Players.LocalPlayer
local chr = plr.Character or plr.CharacterAdded:Wait()
local HRP = chr:WaitForChild("HumanoidRootPart")
local hrpPos = HRP.CFrame.Position
local HUM = chr:FindFirstChildWhichIsA("Humanoid")
local Mouse = plr:GetMouse()
local mousePos = Mouse.Hit.Position
local UIS = game:GetService("UserInputService")
local DefaultWalkSpeed = 16
local DefaultJumpHeight = 7.2
local DB = game:GetService("Debris")
UIS.InputBegan:Connect(function(input, chating)
if not chating then
if input.KeyCode == Enum.KeyCode.Z then
local BodyPosition = Instance.new("BodyPosition", HRP)
BodyPosition.Name = "BodyPosition"
BodyPosition.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
BodyPosition.D = 0
BodyPosition.P = 999999
BodyPosition.Position = HRP.Position
local BodyGyro= Instance.new("BodyGyro", HRP)
BodyGyro.Name = "BodyGyro"
BodyGyro.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
BodyGyro.D = 100
BodyGyro.P = 999999
BodyGyro.CFrame = CFrame.lookAt(hrpPos, Vector3.new(mousePos.X, mousePos.Y, mousePos.Z))
HUM.WalkSpeed = 0
HUM.JumpHeight = 0
repeat
mousePos = Mouse.Hit.Position
BodyGyro.CFrame = CFrame.new(hrpPos, Vector3.new(mousePos.X, mousePos.Y, mousePos.Z))
wait()
until HoldingSkill.Value == false
DB:AddItem(BodyPosition, 0)
DB:AddItem(BodyGyro, 0)
HUM.WalkSpeed = DefaultWalkSpeed
HUM.JumpHeight = DefaultJumpHeight
end
end
end)
And here is my video about my trouble(sorry for lagging video my pc have low specs)
robloxapp-20221025-1846103.wmv (1.9 MB)
If anyone know how to fix this please comment I will take any advice Thank you so much!