I am making a gun
it uses Motor6D to connect the player torso to the gun every time the player equips it.
script(body attach is just something that holds the gun by weld)
local players = game:GetService("Players")
local rs = game:GetService("ReplicatedStorage")
players.PlayerAdded:Connect(function(plr)
plr.CharacterAppearanceLoaded:Connect(function(char)
local torso = char:FindFirstChild("Torso")
if torso then
local M6D = Instance.new("Motor6D")
M6D.Parent = torso
M6D.Name = "ToolGrip"
print("ToolGrip Created")
end
end)
end)
rs.ConnectM6D.OnServerEvent:Connect(function(plr)
local char = plr.Character
local bp = plr.Backpack
local pistol = bp.Pistol
local gun = pistol.Gun
local bodyAttach = gun.BodyAttach
local torso = char:FindFirstChild("Torso")
if torso then
torso.ToolGrip.Part0 = torso
torso.ToolGrip.Part1 = bodyAttach
end
end)
rs.DisconnectM6D.OnServerEvent:Connect(function(plr)
local char = plr.Character
local torso = char:FindFirstChild("Torso")
if torso then
torso.ToolGrip.Part1 = nil
end
end)
Remember that because “Torso” is where the Motor6D instance is parented to this will only work for R6 avatars as for R15 avatars that joint is split into a lower torso and upper torso.
It’s also best to avoid using the parent parameter, more about that here.
I’ve swapped CharacterAdded for CharacterAppearanceLoaded as that fires when the character’s avatar is loaded.
You’re also referencing the tool inside StarterPack, not the tool inside the backpack folder of the player instance (which is where tools are copied to from the StarterPack folder each time the player’s character reloads/spawns etc.).
local weapon = script.Parent
local Gun = weapon:FindFirstChild("Gun")
local rs = game:GetService("ReplicatedStorage")
weapon.Equipped:Connect(function()
local char = weapon.Parent
local torso = char:FindFirstChild("Torso")
if torso then
rs.ConnectM6D:FireServer()
torso.ToolGrip.Part0 = torso
torso.ToolGrip.Part1 = Gun:FindFirstChild("BodyAttach")
end
end)
weapon.Unequipped:Connect(function()
local plr = weapon.Parent.Parent
local char = plr.Character
local torso = char:FindFirstChild("Torso")
if torso then
rs.DisconnectM6D:FireServer()
end
end)
and the necessary changes to the local script as well.
If you don’t want to use @Forummer’s script for some reason, then the only real issue I see is naming your location variable the same as your argument in your remote event. You really don’t need that variable at all.
It looks like you’re trying to use Headstackk’s animating tutorial (the one I use as well), and everything else looks fine except for that variable.
and yeah, not only is the original value for the variable “location” being overridden by its redeclaration as a parameter and thus the received value the client shouldn’t be sending data when firing the server anyway, it’s best to just call FireServer() with no arguments.
It’s only because it’s unnecessary. It’s wrong to go overboard with hack prevention and security. The client should be trusted enough to take care of most functions without sending it all to the server.
I don’t think removing one parameter is going “overboard” on exploit prevention, especially when the thing you’re removing could result in some messed up stuff, but I don’t wanna talk about what is right and what is wrong here.