Criminality Running system

So i’ve been trying to make this running system for a while now but it’s very glitchy and i’m just not satisfied! here is what i’ve been trying to make : Suggestions for Criminality V2 - YouTube

As you can see there is this perfect camera bobble there is an animation that fits pretty well and finally that stamina bar i just can’t seem to make all of that work! Pls if anyone could help me with this (You are amazing!)

And yeah thx in advance!

2 Likes

What do you have so far? It is difficult to help without having the code you have already written.

Where are the main problems?

Ok so here are my 2 scripts one for the camera and another for the running (note that i didn’t make the stamina system yet!)

(—Running script—)

–Variables
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local Properties = {FieldOfView = 80} --Fov
local Info = TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut) --Tween
local T = game:GetService(“TweenService”):Create(game.Workspace.CurrentCamera, Info, Properties)
local rProperties = {FieldOfView = 70} --DefaultFov
local rInfo = TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut) --Tween
local rT = game:GetService(“TweenService”):Create(game.Workspace.CurrentCamera, rInfo, rProperties)
local character = script.Parent
local humanoid = character:WaitForChild(“Humanoid”)

local camerabobcf = CFrame.new()
local cam = workspace.CurrentCamera
local humanoid = game.Players.LocalPlayer.Character:FindFirstChild(“Humanoid”)
local UserInputService = game:GetService(“UserInputService”)

local Animation = Instance.new(“Animation”)
Animation.AnimationId = “rbxassetid://6891970873”

local RunAnim = humanoid:LoadAnimation(Animation)
local UserInputService = game:GetService(“UserInputService”)

– Detect keys pressed function –

local function isKeyPressed(input)
local keysPressed = UserInputService:GetKeysPressed()
for _, key in ipairs(keysPressed) do
if key.KeyCode == input then
return true
end
end
return false
end

– The input began –
UserInputService.InputBegan:Connect(function(inputObject, gameProcessedEvent)

if isKeyPressed(Enum.KeyCode.LeftShift ) and isKeyPressed(Enum.KeyCode.W ) then
	
	humanoid.WalkSpeed = 30
	T:Play()
	RunAnim:Play()
			
	humanoid:GetPropertyChangedSignal("Jump"):Connect(function()
		humanoid.WalkSpeed = 16
		rT:Play()
		RunAnim:Stop()
	end)
	
	elseif (isKeyPressed(Enum.KeyCode.W ) and isKeyPressed(Enum.KeyCode.A)) then 
	humanoid.WalkSpeed = 16
	rT:Play()
	RunAnim:Stop()

	
end

end)

– The input ended –
UserInputService.InputEnded:Connect(function(inputObject, gameProcessedEvent)
if inputObject.KeyCode == Enum.KeyCode.LeftShift or inputObject.KeyCode == Enum.KeyCode.W then
player.Character.Humanoid.WalkSpeed = 16
rT:Play()
RunAnim:Stop()
end
end)

(—Camera script—)

local camerabobcf = CFrame.new()
local cam = workspace.CurrentCamera
local humanoid = game.Players.LocalPlayer.Character:FindFirstChild(“Humanoid”)
local UserInputService = game:GetService(“UserInputService”)

game:GetService(“RunService”).RenderStepped:Connect(function()

cam.CFrame = cam.CFrame
	* camerabobcf
if humanoid.MoveDirection.Magnitude > 0 then
	
		camerabobcf = camerabobcf:Lerp(CFrame.new() * CFrame.Angles(
			0,
			0, 
			0.02 * math.sin(tick() * 8)) -- intensity * math.sin(tick() * speed))
			,.1)
	end

end)

1 Like

Okay thank you. What is your main problem? I will have a look.

Ok my 3 main problems are :

1- when i climb something then just jump the running animation cancels and plays the walking animation instead of the running one !

2 - I rlly don’t know how to make it compatible with a stamina bar.

3- I want the camera bobble to be faster when the player runs.

Ok, that’s all i can think of (hope it’s not too much) an srry again!

For number 1 - The animation is not a problem in my test.

For number 2 - I have made a needs system, so it should be the same code

So for number 3 I just made it. We are adding an if-statement into the camera script so it looks like this:

local camerabobcf = CFrame.new()
local cam = workspace.CurrentCamera
local humanoid = game.Players.LocalPlayer.Character:FindFirstChild("Humanoid")
local UserInputService = game:GetService("UserInputService")
local i

game:GetService("RunService").RenderStepped:Connect(function()
	if game.Players.LocalPlayer.Character.Humanoid.WalkSpeed == 30 then
		i = 30
	else
		i = 8
	end
	cam.CFrame = cam.CFrame
		* camerabobcf
	if humanoid.MoveDirection.Magnitude > 0 then

		camerabobcf = camerabobcf:Lerp(CFrame.new() * CFrame.Angles(
			0,
			0, 
			0.02 * math.sin(tick() * i)) -- intensity * math.sin(tick() * speed))
			,.1)
	end
end)

As you can see I replaced the speed with a variable. Then the if statement checks if the player is running or not.
I hope this may help you!

Oh yeah , i rlly didn’t think of doing that thx , but for number 2 tho?

We can add this in the camera script too. If i == 30 then it goes down, if it is 8 it goes up.

Oh ok.Should i name the stamina bar anything specefic or…?

No. It is only important that you use the Scale and not the offset. An example how it can look like is this:

Bild_2021-06-20_151220
Bild_2021-06-20_151253

And then some code you may use if you create new Localscript in the same position as in my pictures:

local size = script.Parent.Frame.Hunger.Base.Bar.Size.X.Scale
local stanima
while wait() do
if game.Workspace[player].Humanoid.WalkSpeed == 30 then
if size > 0 then
stanima = -0.0001 (or whatever you want)
end
else
stanima = 0.0001
end
script.Parent.Frame.Hunger.Base.Bar.Size = UDim2.fromScale(size+stanima,1)
end

You need to add that the run animation stops if the size is smaller or equal 0. You may do this with a RemoteEvent.

Ok can you show me how to adjust it with the event?

We do not need to create one. We can just easily set the walking speed to 16 again. Sorry, my bad :sweat_smile:
Just replace the code I send you with this:

local size = script.Parent.Frame.Hunger.Base.Bar.Size.X.Scale
local stanima
while wait() do
if game.Workspace[player].Humanoid.WalkSpeed == 30 then
if size > 0 then
stanima = -0.0001 (or whatever you want)
else
game.Workspace[player].Humanoid.WalkSpeed = 16
end
else
stanima = 0.0001
end
script.Parent.Frame.Hunger.Base.Bar.Size = UDim2.fromScale(size+stanima,1)
end
1 Like

Ok thx now i’m just going to test the code and see.

I just got one more question what’s the difference between scale and offset?

Scale is depending on the size of the screen or a parented Frame and offset is a absolute size.
So for example if you create a frame and set the x-axis to 0.5 and the y-axis to 1, the gui will fill out half of the screen.
If you set the offset to for example 500x300 you will get the size in pixels. If you have a full hd monitor with 1920x1080 or a 4k with more, the GUI will have the same size everytime while the scale-GUI´s size is relative.

So how to use the scale? And how to use the offset?

Go to the properties-window in studio (mostly under the explorer) and search there for size. If you click the arrow you can see the settings there.

1 Like