Hey! I just made a goalkeeper script, but I can’t rotate it manually.
local NPC = script.Parent
local ball = workspace:WaitForChild("Ball")
local region = workspace:WaitForChild("Region")
while true do
local ballPos = ball.Position
local regionPos = region.Position
if ballPos.Z < regionPos.Z - region.Size.Z/2 then
NPC.HumanoidRootPart.CFrame = CFrame.new(regionPos.X, regionPos.Y, regionPos.Z - region.Size.Z/2)
elseif ballPos.Z > regionPos.Z + region.Size.Z/2 then
NPC.HumanoidRootPart.CFrame = CFrame.new(regionPos.X, regionPos.Y, regionPos.Z + region.Size.Z/2)
else
NPC.HumanoidRootPart.CFrame = CFrame.new(regionPos.X, regionPos.Y, ballPos.Z)
end
wait(0.05)
end
What I mean is, I might want to change the rotation some time, but it is stuck at (0, 0, 0).
I tried adding this to the script, but then it didn’t work anymore:
This above is what I used for rotation, even if += works, you did it different than mine, try that then tell me what happened, if it doesnt work, i’ll try yours
A CFrame has positional and rotational data in it. CFrame.new() only makes a CFrame with positional data, and no rotational data (rotation at 0, 0, 0).
CFrame.Angles creates a CFrame with rotation, but no position.
If you set a part’s CFrame made by CFrame.new, you set the part’s position to whatever you like, but it will not have any rotation. This is literally the reason why it appears to rotate only once.
local NPC = script.Parent
local ball = workspace:WaitForChild("Ball")
local region = workspace:WaitForChild("Region")
while true do
NPC.HumanoidRootPart.CFrame.Rotation = Vector3.new(0, -90, 0)
local ballPos = ball.Position
local regionPos = region.Position
if ballPos.Z < regionPos.Z - region.Size.Z/2 then
NPC.HumanoidRootPart.CFrame = CFrame.new(regionPos.X, regionPos.Y, regionPos.Z - region.Size.Z/2)
elseif ballPos.Z > regionPos.Z + region.Size.Z/2 then
NPC.HumanoidRootPart.CFrame = CFrame.new(regionPos.X, regionPos.Y, regionPos.Z + region.Size.Z/2)
else
NPC.HumanoidRootPart.CFrame = CFrame.new(regionPos.X, regionPos.Y, ballPos.Z)
end
wait(0.05)
end
Modified script ^
It does say rotation cannot be assigned to, yet it does rotate.