Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I clone this Sheathe onto the Player's Torso then weld it?

Okay, so what I was aiming for is this Sheathe to be cloned onto the player's Torso and welded as soon as they spawned. These are the pictures on what I need it to look like. Front View: gyazo.com/d2dacf03a837e3c2e5f65802ea4497da Right Side View: gyazo.com/395f3f46c15ca87d96ebffab7177aec2 By the way that's my other account since I forgot the pin and I can't change the description. The Code for the Server Script inside the Gear:

--Variables for all
local par = script.Parent
local animations = par.Animations
local sounds = par.Sounds
local clones = par.Clones

--Adds KatanaSheathe to Player
game.Players.PlayerAdded:Connect(function(player)
	local char = player.Character
	local hum = char:WaitForChild("Humanoid")
	local humrp = char:WaitForChild("HumanoidRootPart")
	local torso = char:WaitForChild("Torso")
	local WC = Instance.new("WeldConstraint",torso)
	local KS = clones.KatanaSheathe:Clone()
	KS.Parent = torso
	KS.CFrame = torso.CFrame * CFrame.new(-0.75,-0.5,0)
	KS.Tranparency = 0
end)

--When Player Equips
par.Equipped:Connect(function(player)
	par.Handle.PartA.Enabled = true
	par.Handle.PartB.Enabled = true
	wait(1)
	par.Handle.PartA.Enabled = false
	par.Handle.PartB.Enabled = false
end)

--When Player Unequips
par.Unequipped:Connect(function(player)
	local char = player.Character
	local hum = char:WaitForChild("Humanoid")
	local humrp = char:WaitForChild("HumanoidRootPart")
	local torso = char:WaitForChild("Torso")
end)

I'm not good at functions so I'm just testing and checking the output every change I make. Another odd thing is that nothing appears in the output when I spawn and when I unequip the tool it says this in the output.

11:50:30.466 - Players.Mr_popscicleYT.Backpack.Katana.Sheathe:31: attempt to index nil with 'Character'

In-game the Sheathe does not appear so I'm kind of confused at this point. Am I structuring the code wrong? Parented the Sheathe to soon or is it the CFrame and Transparency?

Thanks for reading this.

1 answer

Hello. The reason it errors is that the player's character hasn't loaded in yet, so player.Character would be nil. This is easy to solve. Just add a player.CharacterAdded event connected to a function. Also, there is no parameter for Tool.Unequiped. Although this is also easy it solve by having the knowledge that an unequipped tool goes in the player's backpack - a child of the player, so you can just use script.Parent.Parent.Parent. Try this:

--Variables for all
local par = script.Parent
local animations = par.Animations
local sounds = par.Sounds
local clones = par.Clones

--Adds KatanaSheathe to Player
game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		local hum = char:WaitForChild("Humanoid")
	    local humrp = char:WaitForChild("HumanoidRootPart")
	    local torso = char:WaitForChild("Torso")
	    local WC = Instance.new("WeldConstraint",torso)
	    local KS = clones.KatanaSheathe:Clone()
	    KS.Parent = torso
	    KS.CFrame = torso.CFrame * CFrame.new(-0.75,-0.5,0)
	    KS.Tranparency = 0
	end)
end)

--When Player Equips
par.Equipped:Connect(function(player)
    par.Handle.PartA.Enabled = true
    par.Handle.PartB.Enabled = true
    wait(1)
    par.Handle.PartA.Enabled = false
    par.Handle.PartB.Enabled = false
end)

--When Player Unequips
par.Unequipped:Connect(function(player)
    local char = script.Parent.Parent.Parent.Character -- The character
    local hum = char:WaitForChild("Humanoid")
    local humrp = char:WaitForChild("HumanoidRootPart")
    local torso = char:WaitForChild("Torso")
end)

Please upvote and accept this answer if it helped.

2 comments

0

I checked the output and no errors occurred although I got a warning in the Output that said "13:16:36.963 - Infinite yield possible on 'Players.Mr_popscicleYT:WaitForChild("Humanoid")'" Is that a good thing? Plus the Sheathe isn't visible so I still have to make changes. Thanks for the help though!

0

Oh, I see the problem. Try now, I've edited it.

This discussion is preserved as it was. New answers, comments, and votes are closed.