Hello. I am making a football game with a goalkeeper that would position itself in Z axis of the ball. Below is what I made. But there is an issue. I do not want goalkeeper to always stand next to ball and player to not be able to score. Basically I want goalkeeper to have reaction time.
local Gk = game.Workspace.Goalkeeper
local Ball = game.Workspace.Ball
while true do task.wait()
Gk:MoveTo(Vector3.new(
171.884,
-38.478,
Ball.Position.Z))
end
local Gk = game.Workspace.Goalkeeper
local Ball = game.Workspace.Ball
while true do
task.wait(math.random()*1.5)
Gk:MoveTo(Vector3.new(
171.884,
-38.478,
Ball.Position.Z))
end
this will randomly wait between 0 and 1.5 seconds everytime the loops fires
local Gk = game.Workspace.Goalkeeper
local Ball = game.Workspace.Ball
local goal = {
CFrame = CFrame.new(171.884, -38.478, Ball.Position.Z) * CFrame.Angles(0,math.rad(90),0)
}--Set the destination for the part to move to.
local info = TweenInfo.new(
0.5, --How long the tween is played for (in seconds)
Enum.EasingStyle.Quad , --The behavior of the tween
Enum.EasingDirection.Out, --The direction of the style
0, --How many times the tween will be repeated
false, --Will the tween play in reverse as well?
0 --Delay between each interpolation.
)
spawn(function()
while true do
wait(0.6)
print(goal)
local Tween = game:GetService("TweenService"):Create(Gk["Goalkeeper (Joe)"].Torso ,info,goal)
Tween:Play()
end
end)
spawn(function()
while true do
wait(1)
goal = {
CFrame = CFrame.new(171.884, -38.478, Ball.Position.Z) * CFrame.Angles(0,math.rad(90),0)
}
end
end)