Help With Tweens

I’m trying to achive this on my sword model but I’m having this error can someone help me with my script (I’m not good at the tweens)

  • What am I trying to achive like this:

[Deleted For Privacy Reasons]

  • What I got:

[Deleted For Privacy Reasons]

The script (Local Script)

local sword = game.Workspace:WaitForChild("swordTest"):WaitForChild("LinkedSword"):WaitForChild("Main")
local ProximityPrompt = game.Workspace:WaitForChild("swordTest"):WaitForChild("LinkedSword"):WaitForChild("PromptPart").ProximityPrompt
local Player = game.Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local AwardBadgeEvent = ReplicatedStorage:WaitForChild("AwardBadgeEvent")

local chancePercentage = 100 
local isAttempted = false 

local particle1 = ProximityPrompt.Parent.Parent.Parent:WaitForChild("testscript").Middle:WaitForChild("1")
local particle2 = ProximityPrompt.Parent.Parent.Parent:WaitForChild("testscript").Middle:WaitForChild("2")
local particle3 = ProximityPrompt.Parent.Parent.Parent:WaitForChild("testscript").Middle:WaitForChild("3")

local swordPullSound = game.SoundService.Misc:WaitForChild("SwordPull")

local isHolding = false
local holdStartedTime = 0

local TweenService = game:GetService("TweenService")

local function fadeOutSound(sound, duration)
	local initialVolume = sound.Volume
	local step = initialVolume / (duration / 0.1)

	task.spawn(function()
		while sound.Volume > 0 do
			sound.Volume = sound.Volume - step
			task.wait(0.1)
		end
		sound:Stop()
		sound.Volume = initialVolume
	end)
end

local function onPromptHold()
	isHolding = true
	holdStartedTime = tick()
	swordPullSound:Play()

	task.spawn(function()
		while isHolding do
			local elapsed = tick() - holdStartedTime

			if elapsed >= 3 and elapsed < 6 then
				particle1.Enabled = true
				particle2.Enabled = false
				particle3.Enabled = false
			elseif elapsed >= 6 and elapsed < 9 then
				particle1.Enabled = true
				particle2.Enabled = true
				particle3.Enabled = false
			elseif elapsed >= 9 then
				particle1.Enabled = true
				particle2.Enabled = true
				particle3.Enabled = true
			end

			task.wait(0.1)
		end
	end)
end

local function tweenSword()
	ProximityPrompt.Enabled = false
	local tweenInfo = TweenInfo.new(
		1,
		Enum.EasingStyle.Linear,
		Enum.EasingDirection.InOut,
		0,
		false,
		0
	)

	local goal = {
		Position = sword.Position + Vector3.new(0, 10, 0),
		Orientation = sword.Orientation + Vector3.new(0, 360, 0)
	}

	local tween = TweenService:Create(sword, tweenInfo, goal)

	local emitParticle = sword:WaitForChild("SwordParticle")

	tween:Play()

	sword.Spin:Play()

	tween.Completed:Connect(function()
		local spinInfo = TweenInfo.new(
			1.5,
			Enum.EasingStyle.Linear
		)

		local spinGoal = {
			Orientation = sword.Orientation + Vector3.new(0, 1440, 0)
		}

		local spinTween = TweenService:Create(sword, spinInfo, spinGoal)
		spinTween:Play()

		spinTween.Completed:Connect(function()
			sword.Transparency = 1
			emitParticle:Emit(50)
			sword.Disappear:Play()
			sword.CanCollide = false
			emitParticle.Enabled = false
		end)
	end)
end

local function onPromptTriggered()
	isHolding = false
	fadeOutSound(swordPullSound, 1)

	particle1.Enabled = false
	particle2.Enabled = false
	particle3.Enabled = false

	if not isAttempted then
		isAttempted = true 

		local randomNumber = math.random(0, 100)

		if randomNumber < chancePercentage then
			tweenSword()
			task.wait(3.5)
			AwardBadgeEvent:FireServer(true)
			game.ReplicatedStorage.Events.LocalInvokeFunction:Fire("TopMessage", "You Pulled The Sword Successfully.")
			game.SoundService.Misc.PullSuccess:Play()
		else
			game.ReplicatedStorage.Events.LocalInvokeFunction:Fire("TopMessage", "You Failed To Pull The Sword.")
			game.SoundService.Misc.PopUpSwordFail:Play()
			print("Try again")
		end
	else
		game.ReplicatedStorage.Events.LocalInvokeFunction:Fire("TopMessage", "You already tried.")
		game.SoundService.Misc.PopUpSwordFail:Play()
	end
end

ProximityPrompt.PromptButtonHoldBegan:Connect(onPromptHold)
ProximityPrompt.Triggered:Connect(onPromptTriggered)

ProximityPrompt.PromptButtonHoldEnded:Connect(function()
	isHolding = false
	fadeOutSound(swordPullSound, 1)
	particle1.Enabled = false
	particle2.Enabled = false
	particle3.Enabled = false
end)

1 Like

ok so, are all of the objects welded to the base of the sword and unanchored? Otherwise they are going to stay in place

All of the objects welded to base part and its anchored, other parts are not anchored

image

Is the basepart of the model set to main? I will test this once I get home

unanchor everything except the main part
also make sure they have been welded well

I already made it. It’s still same

Already made it , double checked even.

use cframe instead of position and see if that helps

1 Like

i think the problem is something to do with welding

you should weld all the parts to the handle you are rotating

I Re-welded everything and still got the same issue

@Fubryl
try

local spinGoal = {
			CFrame = sword.CFrame * CFrame.Angles(0, math.rad(120), 0)
		}

change the degree to what you want
also check the output for any errors
@Fubryl

Zero errors and none of the sword parts spinning. Only sword floating not spinning.

change the rad to 500 and see

This text will be blurred

math.rad(360) is the same as 0. I’m pretty sure it isn’t rotating while raising up because it’s already at that angle.

local goalCFrame = startCFrame * CFrame.new(0, 10, 0) * CFrame.Angles(0, math.rad(360), 0)

Then 1440 degrees as you later spin goal (4 rotations) still ends up at 0, so it’s tweening to that.

I searched 'tween rotate more than 360 degrees and got a few solved posts. Here’s one: Tweening Rotation

1 Like

Maybe try pivoting the whole model instead of the basepart. That should work. You can use :PivotTo()

Can you show an example use of my code? I didn’t really understand the use the use of this function.

that won’t tween the model

Summary

This text will be hidden

@Fubryl
did you check my solution? it didn’t work?
did you check @Scottifly solutions? it didn’t work?

Either turn the sword into a union or use :SetPrimaryPartCFrame() to and update the parts position every time it moves the part.

local tweenService = game:GetService("TweenService")
local info = TweenInfo.new()

local function tweenModel(model, CF)
	local CFrameValue = Instance.new("CFrameValue")
	CFrameValue.Value = model:GetPrimaryPartCFrame()

	CFrameValue:GetPropertyChangedSignal("Value"):Connect(function()
		model:SetPrimaryPartCFrame(CFrameValue.Value)
	end)
	
	local tween = tweenService:Create(CFrameValue, info, {Value = CF})
	tween:Play()
	
	tween.Completed:Connect(function()
		CFrameValue:Destroy()
	end)
end

This code is from a forum i found that you can easily use.

2 Likes

isn’t that what you want?

Summary

This text will be hidden

1 Like