robloxapp-20231126-0739260.wmv (724.1 KB)
How would i make the player not run if only the shift button is pressed, here’s the script that i made:
local UIs = game:GetService("UserInputService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local Camera = game.Workspace.CurrentCamera
local localPlayer = Players.LocalPlayer
local Animsfolder = game:GetService("ReplicatedStorage").Anims
local runanim = Animsfolder.RunAnim
--
local character
local Humanoid
local Ranimtrack
local canrun
--dipake nanti
local Info = TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)
local Properties = { FieldOfView = 80 }
local T = game:GetService("TweenService"):Create(Camera, Info, Properties)
local rProperties = { FieldOfView = 70 }
local rInfo = TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)
local rT = game:GetService("TweenService"):Create(Camera, rInfo, rProperties)
--sprint settings
local BoolValue = false
local Rspeed = 32
local Nspeed = 16
--
local function LoadAnimation(char)
character = char
Humanoid = character:WaitForChild("Humanoid")
Ranimtrack = Humanoid:LoadAnimation(runanim)
end
if player.Character then
LoadAnimation(player.Character)
end
player.CharacterAdded:Connect(LoadAnimation)
local function Toggle()
BoolValue = not BoolValue
if BoolValue then
T:Play()
Ranimtrack:Play()
repeat wait() until not BoolValue
else
rT:Play()
Ranimtrack:Stop()
repeat wait() until BoolValue
end
end
UIs.InputBegan:Connect(function(input,gameProcessed)
if input.UserInputType == Enum.UserInputType.Keyboard and input.KeyCode == Enum.KeyCode.LeftShift and gameProcessed == false then
Humanoid.WalkSpeed = Rspeed
Toggle()
end
end)
UIs.InputEnded:Connect(function(input,gameProcessed)
if input.UserInputType == Enum.UserInputType.Keyboard and input.KeyCode == Enum.KeyCode.LeftShift and gameProcessed == false then
Humanoid.WalkSpeed = Nspeed
Toggle()
end
end)
The Magnitude property of the MoveDirection property of the Humanoid tells you if the player is moving or not. Add this to the bottom of your script.
local function moveDirectionChanged()
local magnitude = Humanoid.MoveDirection.Magnitude -- Get the magnitude
if magnitude == 0 then
-- Player is not moving
if not BoolValue then
Humanoid.WalkSpeed = Nspeed
Toggle()
end
end
end
Humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(moveDirectionChanged)
local UIs = game:GetService("UserInputService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local Camera = game.Workspace.CurrentCamera
local localPlayer = Players.LocalPlayer
local Animsfolder = game:GetService("ReplicatedStorage").Anims
local runanim = Animsfolder.RunAnim
--
local character
local Humanoid
local Ranimtrack
local canrun
--dipake nanti
local Info = TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)
local Properties = { FieldOfView = 80 }
local T = game:GetService("TweenService"):Create(Camera, Info, Properties)
local rProperties = { FieldOfView = 70 }
local rInfo = TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)
local rT = game:GetService("TweenService"):Create(Camera, rInfo, rProperties)
--sprint settings
local BoolValue = false
local Rspeed = 32
local Nspeed = 16
--
local function Toggle()
BoolValue = not BoolValue
if BoolValue then
T:Play()
Ranimtrack:Play()
repeat wait() until not BoolValue
else
rT:Play()
Ranimtrack:Stop()
repeat wait() until BoolValue
end
end
local function moveDirectionChanged()
local magnitude = Humanoid.MoveDirection.Magnitude -- Get the magnitude
if magnitude == 0 then
-- Player is not moving
if not BoolValue then
Humanoid.WalkSpeed = Rspeed
Toggle()
end
end
end
local function LoadAnimation(char)
character = char
Humanoid = character:WaitForChild("Humanoid")
Ranimtrack = Humanoid:LoadAnimation(runanim)
end
if player.Character then
LoadAnimation(player.Character)
end
player.CharacterAdded:Connect(LoadAnimation)
UIs.InputBegan:Connect(function(input,gameProcessed)
if input.UserInputType == Enum.UserInputType.Keyboard and input.KeyCode == Enum.KeyCode.LeftShift and gameProcessed == false then
Humanoid.WalkSpeed = Rspeed
Toggle()
end
end)
UIs.InputEnded:Connect(function(input,gameProcessed)
if input.UserInputType == Enum.UserInputType.Keyboard and input.KeyCode == Enum.KeyCode.LeftShift and gameProcessed == false then
Humanoid.WalkSpeed = Nspeed
Toggle()
end
end)
repeat wait() until Humanoid
Humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(moveDirectionChanged)