Tool position relative to player is not placed properly? + Need help making script serversided

Whenever I am equipping my broom tool, the following happens:
https://gyazo.com/9bc3c6c2a57f3b71a8209cfaa004abb6

The broom is using a motor6d, with handle not required. How can I make it so it has the idle animation, much like how it would if it had handle required (holding it straight out with the right arm)?

I also need help with the localscript for the tool, I don’t know how to make it server-sided (very little experience with remote events)

The particles also aren’t working for some reason, but I’d like to iron out the two major flaws first.

local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local Humanoid = character:WaitForChild("Humanoid")
local tool = script.Parent
local particles = tool.Bristle.ParticleEmitter.Enabled
local animation = tool:WaitForChild("Animation")
local animationTrack = Humanoid:LoadAnimation(animation)

local canRun = true

script.Parent.Activated:Connect(function()
    if canRun == true then
        canRun = false
        animationTrack:Play()
        wait(2)
        particles = true
        wait(3.5)
        particles = false
        canRun = true
        animationTrack:Stop()
    end
end)

script.Parent.Equipped:Connect(function()
    local motor = Instance.new("Motor6D")
	motor.Name = "HandAttach"
	motor.Parent = character.RightHand
    motor.Part0 = character.RightHand
    motor.Part1 = tool.HandAttach
end)

script.Parent.Unequipped:Connect(function()
	local motor = character.RightHand:WaitForChild("HandAttach")
    if motor then
        motor:Destroy()
    end
end)

For the particles you’ll need to set the property. When you use

local particles = tool.Bristle.ParticleEmitter.Enabled

it’s not storing a reference since ParticleEmitter.Enabled is a boolean and booleans are privative. Instead, store a reference to the ParticleEmitter

local particleEmitter = tool.Bristle.ParticleEmitter

and when you want to set the Enabled property use the variable particleEmitter

particleEmitter.Enabled = false
-- or
particleEmitter.Enabled = true

As far as an idle animation, I believe you can just create an AnimationTrack when the tool is equipped, then Stop the animation track when the tool is disabled (and destroy the track and set the variable to nil). Make sure the animation is looped and the priority is low so other animation can play over it.


To get the Motor6 to attach the broom properly, you’ll need to set the Motor6.C0 and Motor6.C1. I don’t know the CFrame math off the top of my head, but I bet someone else does.

Edit:
Try using

motor.C0 *= CFrame.Angles(math.deg(90),0,0)

This code rotates the CFrame 90 degrees around the x axis. If that doesn’t work but rotates the broom, try swapping out the degrees for -90 and the axis too.


If you’re just using the Activated event, you can do all the code from a Script (I believe Activated is replicated to the server). LocalScripts are for client sided things, like UI. RemoteEvents send data from the client to the server and from the server to the client.

Edit: Oh your code is for a LocalScript. The only thing you’ll need to do to make it server sided is move it to a Script and find a new way to get the player:

--local player = game:GetService("Players").LocalPlayer
--local character = player.Character or player.CharacterAdded:Wait()
--local Humanoid = character:WaitForChild("Humanoid")
local tool = script.Parent
local particles = tool.Bristle.ParticleEmitter.Enabled
local animation = tool:WaitForChild("Animation")
local animationTrack-- = Humanoid:LoadAnimation(animation)

local canRun = false

tool.Activated:Connect(function()
	if canRun == true then
		canRun = false
		animationTrack:Play()
		wait(2)
		particles = true
		wait(3.5)
		particles = false
		canRun = true
		animationTrack:Stop()
	end
end)

tool.Equipped:Connect(function()
	canRun = true

	local character = tool.Parent
	local player = game:GetService("Players"):GetPlayerFromCharacter(character)

	local humanoid = character.Humanoid
	animationTrack = humanoid:LoadAnimation(animation)
	local motor = Instance.new("Motor6D")
	motor.Name = "HandAttach"
	motor.Parent = character.RightHand
	motor.Part0 = character.RightHand
	motor.Part1 = tool.HandAttach
	-- TODO: Set motor.C0 and motor.C1
end)

tool.Unequipped:Connect(function()
	canRun = false
	local motor = character.RightHand:WaitForChild("HandAttach")
	if motor then
		motor:Destroy()
	end
	if animationTrack then
		animationTrack:Stop()
		animationTrack:Destroy()
		animationTrack = nil
	end
end)

Let me know if you’ve got any questions :happy2:

2 Likes