Error related to TweenService

Hello, I am making a sword for a game I’m making, and there is a little problem. There seems to be a problem with the tweenservice when I try tweening the cframe angles of my sword, which returns this in the output:

17:06:26.725  Unable to cast to Dictionary  -  Server - Damage:11

I haven’t found a single post on the devforum that could help me out.
This is my code so far:

local DebounceTable = {}
local ts = game:GetService("TweenService")
local ti = TweenInfo.new(1)
local cframe = script.Parent.Handle.Sword.PrimaryPart.CFrame.Rotation
local cframe1 = CFrame.Angles(math.rad(90), 0, 0)
local cframe2 = CFrame.Angles(0, 0, 0)

local cframefortween1 = {CFrame = script.Parent.Handle.Sword.PrimaryPart.CFrame * cframe1}
local cframefortween2 = {CFrame = script.Parent.Handle.Sword.PrimaryPart.CFrame * cframe2}

local tween1 = ts:Create(script.Parent.Handle.Sword.PrimaryPart, ti, {CFrame.Rotation == cframe1})
local tween2 = ts:Create(script.Parent.Handle.Sword.PrimaryPart, ti, {CFrame.Rotation == cframe2})

script.Parent.Activated:Connect(function()
	if tween1.Completed then
		script.Parent:WaitForChild("Handle"):WaitForChild("Sword"):WaitForChild("SwordDamager").Touched:Connect(function(objectThatTouchesTheHitbox)
			if objectThatTouchesTheHitbox.Parent then
				if objectThatTouchesTheHitbox.Parent:FindFirstChild("Humanoid") then
					if DebounceTable[objectThatTouchesTheHitbox.Parent] == true then return end
					DebounceTable[objectThatTouchesTheHitbox.Parent] = true
					objectThatTouchesTheHitbox.Parent.Humanoid:TakeDamage(5)
					wait(2)
					DebounceTable[objectThatTouchesTheHitbox.Parent] = nil
				end
			end
		end)
		tween1.Play()
		tween1.Completed:Wait()
		tween2:Play()
	end
end)

Any help would be really appreciated! (By the way, I got this script from AlvinBlox)

1 Like

Maybe instead of putting {CFrame.Rotation == cframe1} for the property dictionary, you could put something like {CFrame = script.Parent.Handle.Sword.PrimaryPart.CFrame * cframe1}

You made me realize I forgot to add a change, but it still didn’t work:

local DebounceTable = {}
local ts = game:GetService("TweenService")
local ti = TweenInfo.new(1)
local cframe = script.Parent.Handle.Sword.PrimaryPart.CFrame.Rotation
local cframe1 = CFrame.Angles(math.rad(90), 0, 0)
local cframe2 = CFrame.Angles(0, 0, 0)

local cframefortween1 = {CFrame = script.Parent.Handle.Sword.PrimaryPart.CFrame * cframe1}
local cframefortween2 = {CFrame = script.Parent.Handle.Sword.PrimaryPart.CFrame * cframe2}

local tween1 = ts:Create(script.Parent.Handle.Sword.PrimaryPart, ti, {CFrame.Rotation == cframefortween1})
local tween2 = ts:Create(script.Parent.Handle.Sword.PrimaryPart, ti, {CFrame.Rotation == cframefortween2})

script.Parent.Activated:Connect(function()
	if tween1.Completed then
		script.Parent:WaitForChild("Handle"):WaitForChild("Sword"):WaitForChild("SwordDamager").Touched:Connect(function(objectThatTouchesTheHitbox)
			if objectThatTouchesTheHitbox.Parent then
				if objectThatTouchesTheHitbox.Parent:FindFirstChild("Humanoid") then
					if DebounceTable[objectThatTouchesTheHitbox.Parent] == true then return end
					DebounceTable[objectThatTouchesTheHitbox.Parent] = true
					objectThatTouchesTheHitbox.Parent.Humanoid:TakeDamage(5)
					wait(2)
					DebounceTable[objectThatTouchesTheHitbox.Parent] = nil
				end
			end
		end)
		tween1.Play()
		tween1.Completed:Wait()
		tween2:Play()
	end
end)

And this still outputted the same error.

Maybe just say “ts:Create(script.Parent.Handle.Sword.PrimaryPart, ti ,cframefortween1}”

1 Like

What do you mean by that? I don’t really understand.

1 Like
local DebounceTable = {}
local ts = game:GetService("TweenService")
local ti = TweenInfo.new(1)
local cframe = script.Parent.Handle.Sword.PrimaryPart.CFrame.Rotation
local cframe1 = CFrame.Angles(math.rad(90), 0, 0)
local cframe2 = CFrame.Angles(0, 0, 0)

local cframefortween1 = {CFrame = script.Parent.Handle.Sword.PrimaryPart.CFrame * cframe1}
local cframefortween2 = {CFrame = script.Parent.Handle.Sword.PrimaryPart.CFrame * cframe2}

local tween1 = ts:Create(script.Parent.Handle.Sword.PrimaryPart, ti, cframefortween1)
local tween2 = ts:Create(script.Parent.Handle.Sword.PrimaryPart, ti, cframefortween2)

script.Parent.Activated:Connect(function()
	if tween1.Completed then
		script.Parent:WaitForChild("Handle"):WaitForChild("Sword"):WaitForChild("SwordDamager").Touched:Connect(function(objectThatTouchesTheHitbox)
			if objectThatTouchesTheHitbox.Parent then
				if objectThatTouchesTheHitbox.Parent:FindFirstChild("Humanoid") then
					if DebounceTable[objectThatTouchesTheHitbox.Parent] == true then return end
					DebounceTable[objectThatTouchesTheHitbox.Parent] = true
					objectThatTouchesTheHitbox.Parent.Humanoid:TakeDamage(5)
					wait(2)
					DebounceTable[objectThatTouchesTheHitbox.Parent] = nil
				end
			end
		end)
		tween1.Play()
		tween1.Completed:Wait()
		tween2:Play()
	end
end)

Get rid of the CFrame.Rotation == and the {}

Line?

accidentally replied to your post instead of clicking the blue reply button, sorry.

1 Like

I don’t have a CFrame.Rotation on my line, and I need to use {} for those specific lines so I can assign an equation to a variable

The {} are not needed since you already created the dictionary in a variable.

local tween1 = ts:Create(script.Parent.Handle.Sword.PrimaryPart, ti, cframefortween1)
local tween2 = ts:Create(script.Parent.Handle.Sword.PrimaryPart, ti, cframefortween2)

it’s already been removed actually. Yet it still won’t work.

You sure the part exists when you try to tween it?

Yes, I checked the path just now.

Here

CFrame.Rotation == cframe1
CFrame.Rotation == cfram2

They should be

CFrame.Rotation = cframe1
CFrame.Rotation = cframe2

Well i see the problem.

I will try to explain it.

U are directly referencing the “CFrame” Datatype in ur dictionary.

What is happening is its treating it as a array.
So that Tables [1] = “CFrame” Datatype.

To declare Items in Dictionary especially for tweening just encapsulate it in Square brackets.

Solution:

Replace the Variables:

local cframefortween1 = {CFrame = script.Parent.Handle.Sword.PrimaryPart.CFrame * cframe1}
local cframefortween2 = {CFrame = script.Parent.Handle.Sword.PrimaryPart.CFrame * cframe2}

With :

local cframefortween1 = {["CFrame"] = script.Parent.Handle.Sword.PrimaryPart.CFrame * cframe1}
local cframefortween2 = {["CFrame"] = script.Parent.Handle.Sword.PrimaryPart.CFrame * cframe2}

I’ve done it with just the outside brackets by just saying {CFrame = CFrame} and it worked fine.

So the code ran? (ChARrrSsSsssss)

Change

local tween1 = ts:Create(script.Parent.Handle.Sword.PrimaryPart, ti, {CFrame.Rotation == cframe1})
local tween2 = ts:Create(script.Parent.Handle.Sword.PrimaryPart, ti, {CFrame.Rotation == cframe2})

To

local tween1 = ts:Create(script.Parent.Handle.Sword.PrimaryPart, ti, {CFrame.Rotation = cframe1})
local tween2 = ts:Create(script.Parent.Handle.Sword.PrimaryPart, ti, {CFrame.Rotation = cframe2})

Hey guys, I tested the sword today, and it loos like one of your solutions didn’t cause an error, although my sword’s rotation didn’t get tweened. Any help on this?