Help with a knife throwing script

Hey all, I am trying to make a throwable knife that just goes in a straight line when clicked.

I have an error stating: “TweenInfo is not a valid member of Part “Workspace.Kunai_Object” - Server - Script:15”

Here is the script I am using:

local ts = game:GetService("TweenService")

script.Parent.OnServerEvent:Connect(function(plr)
	wait(.3) --startup
	local head = plr.Character.Head
	local sound = script.Parent.Parent.KnifeSound:Clone()
	sound.Parent = head
	sound:Play()
	game.Debris:AddItem(sound,1)
	
	local kunai = game.ReplicatedStorage.Kunai_Object:Clone()
	kunai.Parent = workspace
	kunai.CFrame = plr.Character.HumanoidRootPart.CFrame + plr.Character.HumanoidRootPart.CFrame.lookVector * 5
	
	ts:Create(kunai.TweenInfo.new(3), {CFrame = plr.Character.HumanoidRootPart.CFrame + plr.Character.HumanoidRootPart.CFrame.lookVector * 150}):Play()
	game.Debris:AddItem(kunai,3) --dissapear time
	
	local touched = false
	
	kunai.Touched:Connect(function(hit)
		if hit.Parent:FindFirstChild("Humanoid") and hit.Parent ~= plr.Character and touched == false then
			touched = true
			hit.Parent.Humanoid:TakeDamage(50) -- damage dealt
		end
	end)
end)

As I am just starting to learn with the help of youtube tutorials, if you have any other advice on code layout or better/more efficient ways to do things, please tell me.

Thanks for any help given

1 Like

Dude, you have to define TweenInfo on a separate variable, it is not part of kunai

local tweenInfo = TweenInfo.new(--Yada, yada, yada) 

Search up “TweenInfo” on docs for settings to configure it.

Also, when you create the tween with ts:Create(), you have to put that variable of tweeninfo inside one of the arguments of this function

2 Likes

I am just confused because it worked in the tutorial I was looking at.

1 Like

Oh damn that is strange… I hope it fixed now

Nope. Not fixed :(, i don’t know what to put into tweeninfo and how to implement it

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