Lightsaber not spinning, but making the character go crazy

So…

I am making a lightsaber FROM SCRATCH and I want to make it spin like the Inquisitors’ lightsabers in Star Wars Rebels.

But here is my outcome:


Here is my script:

local spin = game.ReplicatedStorage.Remotes.SpinLightsaber

local players_spinning = {}

game.Players.PlayerAdded:Connect(function(plr)
	players_spinning[plr.Name] = false
end)

spin.OnServerEvent:Connect(function(plr, spinning)
	local saber = plr.Character:WaitForChild("Lightsaber")
	
	local handle = saber.Handle
	local blade = handle.Blade
	
	players_spinning[plr.Name] = not players_spinning[plr.Name]
	
	while players_spinning[plr.Name] do
		handle.CFrame = CFrame.new(handle.CFrame.Position) * CFrame.Angles(0, math.rad(.1), 0)
		blade.CFrame = CFrame.new(blade.CFrame.Position) * CFrame.Angles(0, math.rad(.1), 0)
		wait(.25)
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	players_spinning[plr.Name] = nil
end)

The event is fired when I press E.

1 Like

did you set the laser’s collision false?

In fact I did. (everything is cancollide false) Here is a view of the explorer for more info:
Screen Shot 2020-05-18 at 10.44.54 AM

I may be wrong, but is the blade even moving? It looks like you only set the blade to have a CFrame.Angle of math.rad(.1). Shouldn’t you be adding the angle per each loop instead?

i.e. blade.CFrame = blade.CFrame * ((blade.CFrame - blade.CFrame.Position) + CFrame.Angles(0, math.rad(.1), 0))

First of all that errors.

Second, using + I think will make it error.

Sorry, after researching further, you are doing it correctly. Btw, you do not need to say CFrame.new(blade.CFrame.Position). Simply say blade.CFrame. I think that may be messing things up because you are resetting the rotation of the blade when you refer to only the position component of the blade.

maybe try just rotating the blade instead of the handle?
(Make the handle smaller so it’s at the center of the blade)

That would make it look weird and that would do nothing anyways.

IT ALREADY IS.

maybe u should unanchor ur saber?

Could you elaborate on this? I think @XxELECTROFUSIONxX does make a good point.

Also, you may want to consider this:

the handle is where the tool is basically attached to a player’s hand, if your rotate that then the player might end up rotating too (?)

adjust the grip properties of the tool if it looks weird

edit: don’t parent the other parts to the handle then, parent them directly to the tool

There aren’t any attachments to the player. At least I looked at the explorer AND THERE WERE NO ATTACHMENTS.

oh and also without the handle moving nothing moves…

The way the player holds the saber is from the back of the handle regardless of orientation iirc, so therefore rotating the handle is also going to mess with the orientation of the player. A potential workaround is to create an invisible handle, link it to the other parts of the saber using a Motor6D (as a weld would cause the exact same problem you’re currently having) and then rotate the Motor6D.

1 Like

Just a question: Do I have to parent the Moter6D to the Handle?

This is my script so far:

local spin = game.ReplicatedStorage.Remotes.SpinLightsaber

local players_spinning = {}

game.Players.PlayerAdded:Connect(function(plr)
	players_spinning[plr.Name] = false
end)

spin.OnServerEvent:Connect(function(plr, spinning)
	local saber = plr.Character:WaitForChild("Lightsaber")
	
	local invisHand = saber.Handle
	
	players_spinning[plr.Name] = not players_spinning[plr.Name]
	
	while players_spinning[plr.Name] do
		for i, motor in ipairs(invisHand:GetChildren()) do
			if motor:IsA("Motor6D") then
				motor.CurrentAngle = motor.CurrentAngle + 1
			end
		end
		wait(.5)
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	players_spinning[plr.Name] = nil
end)

You should honestly just do this:


local spin = game.ReplicatedStorage.Remotes.SpinLightsaber

local RunService = game:GetService("RunService")

local players_spinning = {}

game.Players.PlayerAdded:Connect(function(plr)
	players_spinning[plr.Name] = false
end)

local ROTATE_ANGLE = 15 -- how much you want to rotate per second in degrees

spin.OnServerEvent:Connect(function(plr, spinning)
	local saber = plr.Character:WaitForChild("Lightsaber")
	
	local invisHand = player.Character:WaitForChild("RightHand")
	
	players_spinning[plr.Name] = not players_spinning[plr.Name]
	
	while players_spinning[plr.Name] do
		local delta = RunService.Stepped:Wait()
		for i, motor in ipairs(invisHand:GetChildren()) do
			if motor:IsA("Weld") then -- because the handle attach is a weld
				motor.C0 = motor.C0 * CFrame.Angles(math.rad(delta * ROTATE_ANGLE), 0, 0)
			end
		end
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	players_spinning[plr.Name] = nil
end)

Also, you should set the part’s cancollide to false.

1 Like

I hate having to repeat myself over and over again.

Oh and also the thing is rotating but the wrong way… ;-;

You can just adjust the rotation;


local spin = game.ReplicatedStorage.Remotes.SpinLightsaber

local RunService = game:GetService("RunService")

local players_spinning = {}

game.Players.PlayerAdded:Connect(function(plr)
	players_spinning[plr.Name] = false
end)

local ROTATE_ANGLE = 15 -- how much you want to rotate per second in degrees

spin.OnServerEvent:Connect(function(plr, spinning)
	local saber = plr.Character:WaitForChild("Lightsaber")
	
	local invisHand = player.Character:WaitForChild("RightHand")
	
	players_spinning[plr.Name] = not players_spinning[plr.Name]
	
	while players_spinning[plr.Name] do
		local delta = RunService.Stepped:Wait()
		for i, motor in ipairs(invisHand:GetChildren()) do
			if motor:IsA("Motor6D") then -- because the handle attach is a weld
				motor.C0 = motor.C0 * CFrame.Angles(0, 0, math.rad(delta * ROTATE_ANGLE))
			end
		end
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	players_spinning[plr.Name] = nil
end)

Mind sending a gyazo/video to show how it looks?

The thing isn’t rotating since the motor is NOT a weld.

Set all of the part’s massless property to true inside the tool

Screen Shot 2020-05-18 at 11.33.06 AM

Are you sure? Because there is a weld when you equip the tool called something like ToolGrip.