Dagger (Tween movement for a tool)

I am trying to make a dagger that when clicked will move forward 3 studs and then return back to its original position.

Is there a way to do this smoothly?

Here is my messed up code that doesn’t work :skull:

local can = true
local tool = script.Parent
script.Parent.Click.OnServerEvent:Connect(function(player,mouse)
	if can == true then
		can = false
		tool.Grip.Position += Vector3.new(0,3,0)
		wait(.5)
		tool.Grip.Position += Vector3.new(0,3,0)
		can = false
	end
end)
1 Like

You can use tweenservice: TweenService | Roblox Creator Documentation

Yes I know that I’m asking how to do that

Let me know if this works:

local TweenService = game:GetService("TweenService")
local tool = script.Parent
local can = true
local Info = TweenInfo.new(
	0.1,
	Enum.EasingStyle.Sine
	,Enum.EasingDirection.In
	,0
	,false
	,0
)
local Goals = {
	Position = tool.Grip.Position + Vector3.new(0,3,0)
}
script.Parent.Click.OnServerEvent:Connect(function(player,mouse)
	if can then
		can = false
		TweenService:Play(tool.Grip,Info,Goals):Play()
		task.wait(.5)
		TweenService:Play(tool.Grip,Info,Goals):Play()
		can = false
	end
end)

I get an error code that says:

“Play is not a valid member of TweenService “TweenService””

Oh oops.

local TweenService = game:GetService("TweenService")
local tool = script.Parent
local can = true
local Info = TweenInfo.new(
	0.1,
	Enum.EasingStyle.Sine
	,Enum.EasingDirection.In
	,0
	,false
	,0
)
local Goals = {
	Position = tool.Grip.Position + Vector3.new(0,3,0)
}
script.Parent.Click.OnServerEvent:Connect(function(player,mouse)
	if can then
		can = false
		TweenService:Create(tool.Grip,Info,Goals):Play()
		task.wait(.5)
		TweenService:Create(tool.Grip,Info,Goals):Play()
		can = false
	end
end)

It says:

“Unable to cast value to Object”

I made the place where it errored have — on it so you know where it errored

local TweenService = game:GetService("TweenService")
local tool = script.Parent
local can = true
local Info = TweenInfo.new(
	0.1,
	Enum.EasingStyle.Sine
	,Enum.EasingDirection.In
	,0
	,false
	,0
)
local Goals = {
	Position = tool.Grip.Position + Vector3.new(0,3,0)
}
script.Parent.Click.OnServerEvent:Connect(function(player,mouse)
	if can then
		can = false
		---TweenService:Create(tool.Grip,Info,Goals):Play()---
		task.wait(.5)
		TweenService:Create(tool.Grip,Info,Goals):Play()
		can = false
	end
end)
local TweenService = game:GetService("TweenService")
local tool = script.Parent
local can = true
local Info = TweenInfo.new(
	0.1,
	Enum.EasingStyle.Sine
	,Enum.EasingDirection.In
	,0
	,false
	,0
)
local Goals = {
	Grip = tool.Grip * CFrame.new(0,3,0)
}

script.Parent.Click.OnServerEvent:Connect(function()
	if can then
		can = false
		TweenService:Create(tool,Info,Goals):Play()
		task.wait(.5)
		TweenService:Create(tool,Info,Goals):Play()
		can = false
	end
end)

I am doing some editing but this seems to have worked.

I do have one more question,
Is there a way to make the arm follow the tool or do you just have to use an animation?

You should make a seperate topic on that, but I recommend basing your script on this video: Rotate Head to Camera Direction! - Roblox (Motor6D CFrame and Trigonometry) - YouTube

1 Like

I private your help! Thank you very much!

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.