I’m trying to figure out how for the game to know when a player spins around fully. 310 degrees or more to be exact. I’m on the right track, and it kind of works, but not really.
Basically, when the value of script.Parent changes to true, the player will be put in stagger. They can spin left or right (not both), depending on the type of stagger to break out of it. They have about 1 second to spin around to at least 310 degrees to break out, and if they fail then they must wait the full second and one half.
But this is more or less besides the point here. This system works fine. The problem arises when detecting the Player’s orientation. With using the script below, everything works swell, but ONLY when the Player’s starting orientation is around 0 degrees. Once the player’s starting script is not around 0 degrees, the more wonky it gets. The main problem being that the Player won’t have to spin around fully to break the stagger. For example, if the Player faces in the direction of 180 degrees, then the Player only has to spin around 180 degrees to break it. On a 90 degree angle, sometime the game will think the Player is going in the opposite direction, or the Player will only have to orient 90 degrees.
This is the current script:
script.Parent.Changed:Connect(function()
if script.Parent.Value == true then
local Direction_Attacked_In = script.Parent.Parent.Direction_Attacked_In.Value
local Starter_Player_Orientation_Value = 0
local Real_Player_Orientation = script.Parent.Parent.Parent.Parent.HumanoidRootPart.Orientation.Y
local Get_Real_Player_Orientation = Real_Player_Orientation
local Get_RPO_Difference = 0
local Will_Spin_Left_Or_Right = 0
local Previous_Orientation_Value = 0
local Too_Fast = false
Get_RPO_Difference = Real_Player_Orientation
Get_Real_Player_Orientation = 0
for i = 1, 67, 1 do
task.wait(0.015)
local Player_Orientation_Before_Spin
local Has_Met_Orientation_Prerequiste = false
local Can_Check = false
Real_Player_Orientation = script.Parent.Parent.Parent.Parent.HumanoidRootPart.Orientation.Y
local Orientation_Threshold_For_Left = 4 + Get_RPO_Difference
local Orientation_Threshold_For_Right = -4 + Get_RPO_Difference
-- Adjusts values if Player's orientation goes over the 180 degree marker. --
if Orientation_Threshold_For_Left > 176 then
Orientation_Threshold_For_Left = (Orientation_Threshold_For_Left - 360)
end
if Orientation_Threshold_For_Right < -176 then
Orientation_Threshold_For_Left = (Orientation_Threshold_For_Right + 360)
end
-- Check if Player has commited to going left or right (Once this happens they cannot break the stagger if they'd commited to the wrong direction). --
if Starter_Player_Orientation_Value > 4 + Get_RPO_Difference and Starter_Player_Orientation_Value <= 180 and Will_Spin_Left_Or_Right == 0 then
Will_Spin_Left_Or_Right = 1
Player_Orientation_Before_Spin = Starter_Player_Orientation_Value
end
if Starter_Player_Orientation_Value < -4 + Get_RPO_Difference and Starter_Player_Orientation_Value >= -180 and Will_Spin_Left_Or_Right == 0 then
Will_Spin_Left_Or_Right = 2
Player_Orientation_Before_Spin = Starter_Player_Orientation_Value
end
-- Check if Player crosses over the 180/-180 degree mark. Adjust values for that. --
if Get_RPO_Difference >= 90 and Real_Player_Orientation <= -90 then
Starter_Player_Orientation_Value = (180 + Real_Player_Orientation) + (180 - Get_RPO_Difference)
elseif Get_RPO_Difference <= -90 and Real_Player_Orientation >= 90 then
Starter_Player_Orientation_Value = (180 - Real_Player_Orientation) + (180 + Get_RPO_Difference)
else
Starter_Player_Orientation_Value = Real_Player_Orientation - Get_RPO_Difference
end
if Will_Spin_Left_Or_Right == 1 and Has_Met_Orientation_Prerequiste == false then
-- Check if player has gone BEYOND the 180 degree mark into the -180 mark. I believe this is where the main problem is. --
if Real_Player_Orientation < 0 then
Starter_Player_Orientation_Value = (Real_Player_Orientation + 360)
Can_Check = true
end
-- Checks if the Player has spun around too quickly. --
if Starter_Player_Orientation_Value - Previous_Orientation_Value > 271.1 then
Too_Fast = true
print(Starter_Player_Orientation_Value - Previous_Orientation_Value)
end
-- This is the same as above. Just for when the player spins right. --
elseif Will_Spin_Left_Or_Right == 2 and Has_Met_Orientation_Prerequiste == false then
if Real_Player_Orientation > 0 then
Starter_Player_Orientation_Value = (Real_Player_Orientation - 360)
Can_Check = true
end
if Starter_Player_Orientation_Value - Previous_Orientation_Value < -271.1 then
Too_Fast = true
print(Starter_Player_Orientation_Value - Previous_Orientation_Value)
end
end
Previous_Orientation_Value = Starter_Player_Orientation_Value
-- Check if the Player has spun around between 410 degrees and 360 degrees (Negative values if the Player spins right). --
if Starter_Player_Orientation_Value >= -50 and Will_Spin_Left_Or_Right == 2 and Can_Check == true then
Starter_Player_Orientation_Value = -360
Has_Met_Orientation_Prerequiste = true
elseif Starter_Player_Orientation_Value <= 50 and Will_Spin_Left_Or_Right == 1 and Can_Check == true then
Starter_Player_Orientation_Value = 360
Has_Met_Orientation_Prerequiste = true
end
print("Player Orientation: ".. Starter_Player_Orientation_Value, "Left Or Right: ".. Will_Spin_Left_Or_Right, "Total Orientation: ".. Total_Orientation_Value, "Current Orientation Minus Previous Orientation: ".. Starter_Player_Orientation_Value - Previous_Orientation_Value, Too_Fast)
-- If attacked with the opponents weapon moving to the player's left side. If the statement is true, then the stagger breaks. --
if Direction_Attacked_In == 0 and Starter_Player_Orientation_Value >= 310 and Too_Fast == false then
script.Parent.Value = false
script.Parent.Parent.Parent.Blade.BrickColor = BrickColor.new("Medium blue")
break
-- If attacked with the opponents weapon moving to the player's right side. If the statement is true, then the stagger breaks.--
elseif Direction_Attacked_In == 1 and Starter_Player_Orientation_Value <= -310 and Too_Fast == false then
script.Parent.Value = false
script.Parent.Parent.Parent.Blade.BrickColor = BrickColor.new("Medium blue")
break
end
end
end
end)
Essentially, I need help improving this script. I’ve been at it for a few days now over a couple scripts and different drafts and this is the best I got. Please feel free to edit the script and send it back to me if you can fix the problem, or just give me the blueprints to scrap it and make a new one if you think there’s a better way.
Help is much appreciated. Thank you very much. If you have any questions about the script above, please ask.