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
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)
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)
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)
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)