How do I make the part move forward using a script

Hello, this is my script:

local AttackVFX = game.Workspace.ATTACKVFX

local function attackfunction()
	UserInputService.InputBegan:Connect(function(input, gameProccesedEvent)
		if input.KeyCode == Enum.KeyCode.F then
			print("Testing")
			local char = game.Players.LocalPlayer.Character
			AttackVFX.CFrame = CFrame.lookAt(char.RightHand.Position,char.RightHand.Position+char.HumanoidRootPart.CFrame.LookVector)
			wait(0.5)
			local instance = AttackVFX
			local Information = TweenInfo.new(0.5,Enum.EasingStyle.Linear,Enum.EasingDirection.In)
			game:GetService("TweenService"):Create(AttackVFX,Information,{CFrame = instance.CFrame + (game.Players.LocalPlayer.Character:FindFirstChild("HumanoidRootPart").CFrame.LookVector * 5)})
		end
	end)
end

attackfunction()

Instead of the part just standing still next to the player, how would I make it move forward? (It is an attack, and the part is a VFX for it)

I’m pretty sure this code is okay, you just need to play the tween.

local Information = TweenInfo.new(0.5,Enum.EasingStyle.Linear,Enum.EasingDirection.In)
local tweenService = game:GetService("TweenService")
local attackTween = tweenService:Create(AttackVFX,Information,{CFrame = instance.CFrame + (game.Players.LocalPlayer.Character:FindFirstChild("HumanoidRootPart").CFrame.LookVector * 5)})
attackTween:Play()

Try this!

local AttackVFX = game.Workspace.ATTACKVFX

local function Attack()
	UserInputService.InputBegan:Connect(function(Input)
		if Input.KeyCode == Enum.KeyCode.F then
			local Character = game.Players.LocalPlayer.Character
            wait(0.5)
			AttackVFX.CFrame = CFrame.lookAt(Character.RightHand.Position, Character.RightHand.Position + Character.HumanoidRootPart.CFrame.LookVector)
			local Information = TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.In)
			game:GetService("TweenService"):Create(AttackVFX, Information, {CFrame = instance.CFrame + (Character:FindFirstChild("HumanoidRootPart").CFrame.LookVector * 5)}):Play()
		end
	end)
end

Attack()
2 Likes
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()

local UIS = game:GetService("UserInputService")
local TS = game:GetService("TweenService")

local function Attack(Input, GPEvent)
	if Input.KeyCode == Enum.KeyCode.F and not GPEvent then
		print("Testing")
		local AttackVFX = game.Workspace.ATTACKVFX
		AttackVFX.CFrame = CFrame.lookAt(Character.RightHand.Position, Character.RightHand.Position + Character.HumanoidRootPart.CFrame.LookVector)
		task.wait(0.5)
		TS:Create(
			AttackVFX,
			TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.In),
			{CFrame = AttackVFX.CFrame + Character.HumanoidRootPart.CFrame.LookVector * 5}
		):Play()
		print("Done")
	end
end

UIS.InputBegan:Connect(Attack)
local UserInputService = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()

local function Attack(Input, GPEvent)
	if Input.KeyCode == Enum.KeyCode.F and not GPEvent then
		local AttackVFX = game.Workspace.ATTACKVFX
		AttackVFX.CFrame = CFrame.lookAt(Character.RightHand.Position, Character.RightHand.Position + Character.HumanoidRootPart.CFrame.LookVector)
		task.wait(0.5)
		TweenService:Create(AttackVFX,TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.In),{CFrame = AttackVFX.CFrame + Character.HumanoidRootPart.CFrame.LookVector * 5}):Play()
	end
end

UserInputService.InputBegan:Connect(Attack)

A simpler version.

play the tween, add :Play() after your tween