New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

Cloning into a tool then binding?

Asked by
BIunem 22
8 days ago

So what I am trying to is when "Pistol" is equipped, a model from lighting will be cloned INTO the "Pistol" and the "Center" of that model will be binded through a Motor6D to the HumanoidRootPart. The reason I am doing this in a LocalScript is so only the LocalPlayer will see the model that gets cloned into the tool. But... this code that I made isn't working!

local Player = game.Players.LocalPlayer
local Character = Player.Character
local sgun = game.Lighting.Guns.sgun
local gtool = script.Parent
     gtool.Equipped:Connect(function(mouse)
    sgun:Clone().Parent = Character.Backpack.Pistol
    local cgun = Character.Backpack.Pistol.sgun
    local xbody = gtool.sgun.Center
    local UpperT = Character:FindFirstChild("HumanoidRootPart")
    local TWeld = Instance.new("Motor6D")
    TWeld.Part0 = UpperT
    TWeld.Part1 = xbody
    TWeld.C0 = UpperT.C1
    TWeld.C1 = xbody.C1
    TWeld.Parent = UpperT
end)

function Tool_Unequip()
    cgun:Destroy()
    TWeld:Destroy()
0
Could you tell us what's not working? Feahren 1746 — 8d
0
Nothing is working. BIunem 22 — 8d
0
No errors appear in the out BIunem 22 — 8d
0
Output* BIunem 22 — 8d
View all comments (4 more)
0
I check the tool after I had equipped it and no cloned model is in the tool. So basically, the entire script won’t work and there are no red or blue underlines in the code. BIunem 22 — 8d
0
Line 6. Backpack isn't a descendant of the Character, it's of the Player. So: .Parent = Player.Backpack.Pistol. Same for line 7, Player not Character Shawnyg 3935 — 8d
0
Thank you! BIunem 22 — 8d
0
So is that the solution for the whole script? :P BIunem 22 — 8d

1 answer

Log in to vote
0
Answered by 8 days ago

from looking at the comments i think i found it?

local Player = game.Players.LocalPlayer
local Character = Player.Character
local sgun = game.Lighting.Guns.sgun
local gtool = script.Parent
     gtool.Equipped:Connect(function(mouse)
    sgun:Clone().Parent = player.Backpack.Pistol -- your finding the character the character has the humanoid so i think i found the error
    local cgun = player.Backpack.Pistol.sgun
    local xbody = gtool.sgun.Center
    local UpperT = Character:FindFirstChild("HumanoidRootPart")
    local TWeld = Instance.new("Motor6D")
    TWeld.Part0 = UpperT
    TWeld.Part1 = xbody
    TWeld.C0 = UpperT.C1
    TWeld.C1 = xbody.C1
    TWeld.Parent = UpperT
end)

function Tool_Unequip()
    cgun:Destroy()
    TWeld:Destroy()
0
Thanks! BIunem 22 — 8d
Ad

Answer this question