I am trying to make a bat as a test to help me learn scripting, but I’ve come along an issue where equipping the bat floods the torso with Motor6Ds, which I will use to animate the swing.
The plan was to delete them after the bat is unequipped, and when the bat is equipped the Motor6D will be there to animate the swing.
The issue is I’m not sure how I can delete the Motor6D after I am done with it?
Thanks for helping in advance, but here is a picture of my very noob code as a sample of what I used.
local UIS = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Tool = script.Parent
local player = game.Players.LocalPlayer
Tool.Equipped:connect(function()
local Motor = Instance.new ("Motor6D")
Motor.Parent = script.Parent.Parent.Torso
end)
Tool.Unequipped:Connect(function()
Motor = nil
end)
local UIS = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Tool = script.Parent
local player = game.Players.LocalPlayer
Tool.Equipped:connect(function()
local Motor = Instance.new ("Motor6D")
Motor.Name = "NewMotor"
Motor.Parent = script.Parent.Parent.Torso
end)
Tool.Unequipped:Connect(function()
Motor = nil
-- do what ever you want here'
NewMotor:Destroy()
end)
When I dequip the tool, the script disappears with it so I can’t find the Torso through script.parent.
Is there a way to find the Motor6D even when the script is not inside the player’s model itself?
And I can’t do workspace.CrazyGrapefruit32 because that will not work for other players, so I’m lost.
You can try use this and see if it works, however you might need to change the code up a bit as to when you want it deleted @CrazyGrapefruit32, dm me if you have any questions.