That might be because its trying to rotate in both directions?
To prioritize the most recent input, you should Pause the other tween before Playing one
like replace
RotateTween:Play()
with
Rotate:Pause() --incase you renamed it, then replace Rotate here with that
RotateTween:Play()
local StartActions = {
ActionW = function(player) --Function when W is pressed
Rotate:Pause()
RotateTween:Play()
end;
ActionA = function(player) --Function when A is pressed
print(player.Name.." pressed A")
end;
ActionS = function(player) --Function when S is pressed
RotateTween:Pause()
Rotate:Play()
end;
ActionD = function(player) --Function when D is pressed
print(player.Name.." pressed D")
end;
}
local EndActions = {
ActionW = function(player) --Function when W is no longer pressed
RotateTween:Pause()
end;
ActionA = function(player) --Function when A is no longer pressed
print(player.Name.." stopped pressing A")
end;
ActionS = function(player) --Function when S is no longer pressed
Rotate:Pause()
end;
ActionD = function(player) --Function when D is no longer pressed
print(player.Name.." stopped pressing D")
end;
}
Paste this between the local Rotate line and the local StartActions line;
RotateTween.Completed:Connect(function(state)
if state == Enum.PlaybackState.Completed then
RotateTween:Play()
end
end)
Rotate.Completed:Connect(function(state)
if state == Enum.PlaybackState.Completed then
Rotate:Play()
end
end)
and replace TI with this:
local TI = TweenInfo.new(10,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut,0,false,0)
Is there a way to lock the rotation?
For example, the part only rotates along the Y axis
When you rotate the part for a long time it starts to rotate randomly.
it works but it create another problem
when you press for example W for too long and you switch to S it keep spinning at the same direction
the output
W+
W-
S+
S-
I’m sorry, the current way you’re doing it seems way too complicated for no reason.
Here’s my take:
client:
local players = game:GetService "Players"
local replicated_storage = game:GetService "ReplicatedStorage"
local context_action_service = game:GetService "ContextActionService"
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:FindFirstChildOfClass "Humanoid"
local remote = replicated_storage:WaitForChild "TurretInput"
humanoid.Seated:Connect(function(seated: boolean, seat: Seat)
--if not seat:HasTag "TurretSeat" then return end
if seated then
context_action_service:BindActionAtPriority("TurretInput", function(_, state: Enum.UserInputState, input: InputObject)
if state ~= Enum.UserInputState.Begin then return end
remote:FireServer(input.KeyCode)
end, false,10001, Enum.PlayerActions.CharacterForward, Enum.PlayerActions.CharacterBackward, Enum.PlayerActions.CharacterLeft, Enum.PlayerActions.CharacterRight)
else
context_action_service:UnbindAction "TurretInput"
end
end)
server:
local replicated_storage = game:GetService "ReplicatedStorage"
local tween_service = game:GetService "TweenService"
local remote = replicated_storage.TurretInput
local turret_part = workspace.Turret.Head
remote.OnServerEvent:Connect(function(player: Player, input: Enum.KeyCode)
if typeof(input) ~= "EnumItem" then return end
if input ~= Enum.KeyCode.W and input ~= Enum.KeyCode.S then return end
tween_service
:Create(turret_part, TweenInfo.new(0.5), {Orientation = turret_part.Orientation + Vector3.new(0, input == Enum.KeyCode.W and 25 or -25, 0)})
:Play()
end)
first of all, you only want to use the wasd to rotate the turret whenever the player is seated, so use the seated event and ContextActionService (which outclasses UserInputService most of the time) to bind/unbind the input function whenever the player is seated or unseated. Then you send the keycode to the server and the server will rotate the turret by 25 depending on if it was W or S.
An alternate way is to setnetworkownership of the turret to the player, and then rotating the turret on the client.
hope this helps.
Here’s showcase video:
W for right, S for left, and I was spamming W to see if I could knock myself off because I forgot to anchor the seat.
sorry for late response
is this script good?
i’m trying to keep it simple
this is the new script:
local RunService = game:GetService("RunService")
local ROTATION_SPEED = 60 -- degrees per second
local rotatingLeft = false
local rotatingRight = false
RunService.Heartbeat:Connect(function(dt)
local part = workspace.Part
if rotatingLeft then
part.CFrame = part.CFrame * CFrame.Angles(0, math.rad(ROTATION_SPEED * dt), 0)
elseif rotatingRight then
part.CFrame = part.CFrame * CFrame.Angles(0, -math.rad(ROTATION_SPEED * dt), 0)
end
end)
game.ReplicatedStorage.TurretRemote.OnServerEvent:Connect(function(player, began, key)
if key == "W" then
rotatingLeft = began
elseif key == "S" then
rotatingRight = began
end
end)