Hello!
I have script which lets player control a ball, but i have issues with making script slowly decreasing RotVelocity speed.
Here it is:
InputService.InputEnded:Connect(function()
print "stop"
if not InputService:IsKeyDown('W') or not InputService:IsKeyDown('A') or not InputService:IsKeyDown('S') or not InputService:IsKeyDown('D') then
while wait() do
Ball.RotVelocity = Ball.RotVelocity * 0.95
print "stop2"
wait(0.2)
end
end
end)
issue is that i dont know how to make it stop script after RotVelocity will be 0.
And, if i can ask, how can i set limit for RotVelecoty? Thanks for your time, let me know if you need any more info.
Hello! I think i might be trying to put it in the wrong place because it doesnt want to work. Ill send whole script, maybe script itself is blocking something.
local Player = game:GetService('Players').LocalPlayer;
local InputService = game:GetService('UserInputService');
local Camera = workspace.CurrentCamera;
local Settings = {
Speed = 10,
JumpPower = 60,
Size = Vector3.new(5, 5, 5)
}
local Character = Player.Character or Player.CharacterAdded:Wait();
local Humanoid = Character:WaitForChild('Humanoid');
local RayParams = RaycastParams.new();
local Ball = Character:WaitForChild('Ball');
local Connection;
Humanoid.PlatformStand = true
Camera.CameraSubject = Ball
RayParams.FilterType = Enum.RaycastFilterType.Blacklist;
RayParams.FilterDescendantsInstances = {Character};
for _, v in next, Player.Character:GetChildren() do
if v:IsA('BasePart') and v ~= Ball then
v.Massless = true;
v.CanCollide = false;
end
end
Humanoid.Died:Connect(function() Connection:Disconnect() end);
Connection = game:GetService('RunService').RenderStepped:Connect(function(delta)
Humanoid.PlatformStand = true;
Ball.CanCollide = true;
if InputService:IsKeyDown('W') then
Ball.RotVelocity -= Camera.CFrame.RightVector * delta * Settings.Speed
end
if InputService:IsKeyDown('A') then
Ball.RotVelocity -= Camera.CFrame.LookVector * delta * Settings.Speed
end
if InputService:IsKeyDown('S') then
Ball.RotVelocity += Camera.CFrame.RightVector * delta * Settings.Speed
end
if InputService:IsKeyDown('D') then
Ball.RotVelocity += Camera.CFrame.LookVector * delta * Settings.Speed
end
end)
InputService.JumpRequest:Connect(function()
if workspace:Raycast(Ball.Position, Vector3.new(0, -((Ball.Size.Y / 2) + 0.3), 0), RayParams) then
Ball.Velocity = Ball.Velocity + Vector3.new(0, Settings.JumpPower, 0)
end
end)
InputService.InputEnded:Connect(function()
print "stop"
if not InputService:IsKeyDown('W') or not InputService:IsKeyDown('A') or not InputService:IsKeyDown('S') or not InputService:IsKeyDown('D') then
while wait() do
Ball.RotVelocity = Ball.RotVelocity * 0.95
print "wait2"
wait(0.2)
end
end
end)
Ball.RotVelocity = math.clamp(Ball.RotVelocity * 0.95,0,100)
how this works is that the RotVelocity is a vector3 that has 3 number which are x,y and z. I take the individual component of each coordinate and clamp it to -200 and 200 . Why -200 you might ask? cuz you would want to lock the min speed of the ball as the negative side of the max speed as you would want the ball to be able to spin backwards also . I recommend setting 200 as a variable and change the clamp code to something like this