Question about beams

I wish to make a Light Saber type weapon by using beams, I have been successful with creating a working weapon script for this but would like it to toggle he blade bit. When toggled it should either retract into the light saber or retract back out of the light saber. I have tried tweening the attachment position but have failed as it does not work. I’m open to any help and ideas.

script.Parent.Toggle.OnServerEvent:Connect(function()
	if SaberActive == false then
		SaberActive = true
		print(SaberActive)
		Idle:Play(nil, nil, 0)
		script.Parent.B.Attachment.Position:TweenPosition(Vector3.new(0,1,0))
	elseif SaberActive == true then
		SaberActive = false
		print(SaberActive)
		Idle:Stop()
		else
	end
end)
1 Like

Tweening should work fine, it’s probably your code at fault. Try posting the script you used to tween the attachment as well as a visualization of what the attachment does

Says TweenPosition is not a member of attachment.

script.Parent.Toggle.OnServerEvent:Connect(function()
	if SaberActive == false then
		SaberActive = true
		print(SaberActive)
		Idle:Play(nil, nil, 0)
		script.Parent.B.Attachment.Position:TweenPosition(Vector3.new(0,1,0))
	elseif SaberActive == true then
		SaberActive = false
		print(SaberActive)
		Idle:Stop()
		else
	end
end)

That’s because TweenPosition doesn’t exist in an attachment. You should use TweenService and tween its position property

Use tweenService instead of tweenPosition.

--local script
local saber = script.Parent.Parent

saber.Activated:Connect(function()
	local remote = Instance.new("RemoteEvent", game.ReplicatedStorage)
	remote:FireServer()
end)

--script
local event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
local runService = game:GetService("RunService")

local b_Attach = script.Parent.Bottom -- attachment0
local t_Attach = script.Parent.Top -- attachment1
local beam = script.Parent.Beam

local tseries = game:GetService("TweenService")

local info = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 0)

local on = {
	Position = Vector3.new(0,7,0),
}

local off = {
	Position = Vector3.new(0,0.7,0)
	
}

local debounce = false
event.OnServerEvent:Connect(function()
	local tweenOn = tseries:Create(beam, info, on)
	local tweenOff = tseries:Create(beam, info, off)

	debounce = not debounce
	if debounce then
		tweenOn:Play()
	else
		tweenOff:Play()
	end
end)

1 Like