My q to roll script not working

my script not working, idk why. how to fix it?

local UIS = game:GetService(“UserInputService”)
local char = script.Parent

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

local keybind = Enum.KeyCode.Q
local canslide = true

UIS.InputBegan:Connect(function(input,gameprocessed)
if gameprocessed then return end
if not canslide then return end

if input.KeyCode == keybind then
	canslide = false
	
	local playAnim = char.Humanoid:LoadAnimation(slideAnim)
	playAnim:Play()
	
	local slide = Instance.new("BodyVelocity")
	slide.MaxForce = Vector3(1,0,1)*30000
	slide.Velocity = char.HumanoidRootPart.CFrame.lookVector*100
	slide.Parent = char.HumanoidRootPart
	
	for count 1,8 do
		wait(0.1)
		slide.Velocity*=0.7
	end
	playAnim:Stop()
	slide:Destroy()
	canslide = true
end

end)

This isn’t a “q to roll” script, it’s a touch script

1 Like

Format ur code by enclosing them in ```.

function whentouchedOn(hit)
if not hit.Parent:FindFirstChild(“Humanoid”) then return end
if hit.Parent:FindFirstChild(“ForceField”) then return end
Instance.new(“ForceField”, hit.Parent)
end
script.Parent.Touched:Connect(whentouchedOn)

function whentouchedOff(hit)
if not hit.Parent:FindFirstChild(“Humanoid”) then return end
if hit.Parent:FindFirstChild(“ForceField”) then
hit.Parent.ForceField:Destroy()
end
end
script.Parent.TouchEnded:Connect(whentouchedOff)

Also this is a touch script, not a q to rolll script.

1 Like

Did you put the wrong script? Please edit your post.

This is a safezone script (touch part for force field).

1 Like

Vector3() should be replaced with Vector3.new()

This should work.


local ContextActionService = game:GetService('ContextActionService')
local char = script.Parent

local slideAnim = Instance.new("Animation")
slideAnim.AnimationId = 'rbxassetid://8766380894'

local keybind = Enum.KeyCode.Q
local canslide = true

function slide()
	if canslide then
		local playAnim = char.Humanoid:LoadAnimation(slideAnim)
	playAnim:Play()

		local slide = Instance.new('BodyVelocity')
	slide.MaxForce = Vector3.new(1,0,1)*30000
	slide.Velocity = char.HumanoidRootPart.CFrame.lookVector*100
	slide.Parent = char.HumanoidRootPart
	local set = 0
	repeat set = set + 1 slide.Velocity*=0.7 task.wait(.1) until set>=1.8
	playAnim:Stop()
	slide:Destroy()
		canslide = not canslide
	else
		canslide = not canslide
		end
end

ContextActionService:BindAction('Slide',slide,false,keybind)