roll script with anim made by chatgpt
Key RequiredUniversal

roll script with anim made by chatgpt

Universal ScriptPs4sroPs4sro 65.6K views 66 executesUpdated Jul 28, 2024
5.0/ 5(2 votes)
20100% Positive
Lua Script•88 lines (2640 chars)
-- LocalScript in StarterPlayerScripts

local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")

local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local rolling = false
local holdingRollKey = false
local rollDuration = 0.5 -- Duration of each roll in seconds
local rollDistance = 20 -- Distance to roll per roll action

-- Animation setup
local rollAnimationId = "rbxassetid://18537367238"
local rollAnimation = Instance.new("Animation")
rollAnimation.AnimationId = rollAnimationId

local animator = humanoid:FindFirstChild("Animator") or humanoid:WaitForChild("Animator")
local rollAnimTrack = animator:LoadAnimation(rollAnimation)
rollAnimTrack.Looped = true -- Set the animation to loop

local function stopRolling()
rolling = false
rollAnimTrack:Stop()
end

local function performRoll()
local direction = character.PrimaryPart.CFrame.LookVector
local startPosition = character.PrimaryPart.Position
local targetPosition = startPosition + (direction * rollDistance)

local rollStartTime = tick()
local connection
connection = RunService.RenderStepped:Connect(function()
local elapsedTime = tick() - rollStartTime
if elapsedTime > rollDuration then
connection:Disconnect()
if holdingRollKey then
performRoll()
else
stopRolling()
end
return
end

-- Perform raycasting to check for obstacles
local rayOrigin = character.PrimaryPart.Position
local rayDirection = direction * rollDistance * (elapsedTime / rollDuration)
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {character}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local raycastResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)

if raycastResult and raycastResult.Instance.CanCollide then
-- Stop rolling if an obstacle is detected
stopRolling()
connection:Disconnect()
return
end

local progress = elapsedTime / rollDuration
local newPosition = startPosition:Lerp(targetPosition, progress)
character:SetPrimaryPartCFrame(CFrame.new(newPosition, newPosition + direction))
end)
end

local function startRoll()
if rolling then return end
rolling = true
rollAnimTrack:Play()
performRoll()
end

UserInputService.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed then return end
if input.KeyCode == Enum.KeyCode.R then
holdingRollKey = true
startRoll()
end
end)

UserInputService.InputEnded:Connect(function(input, gameProcessed)
if input.KeyCode == Enum.KeyCode.R then
holdingRollKey = false
end
end)

Features & Information

R to roll hold r to become sonic real credit to ocfi for the idea

Community Comments (5)

IntelligenceyzIntelligenceyzFeb 8, 2025(edited)

Shi tuff asf

Ps4sroPs4sroFeb 8, 2025(edited)

@Intelligenceyz crazy cause i made it with ai lol

IntelligenceyzIntelligenceyzFeb 8, 2025(edited)

Lol

IntelligenceyzIntelligenceyzFeb 8, 2025(edited)

Ima release crescent star

IntelligenceyzIntelligenceyzFeb 8, 2025(edited)

It's easier to use

More Scripts for Universal Scripts