Why is instance.new() not working? Confused

Morning guys, so i got a problem while attempting to insert a Motor6D when a player joins, using instance.new() function, what may be the problem? why is instance.new() not working? It must be parented to the torso of a player but there is not Motor6D in Torso.

here the explorer pic. 777 - Album on Imgur

I leave my script here so you can what is going on, and maybe help me out.

Server Sided

game.Players.PlayerAdded:Connect(function(plr)          
	
		local lel = Instance.new("Motor6D", game.Workspace.lucasprofesional23.Torso)
		lel.Name = "ToolGrip"
	
end)

game.ReplicatedStorage.ConnectM6D.OnServerEvent:Connect(function(plr, location)
	
	local char = plr.Character
	char.Torso:WaitForChild("ToolGrip").Part0 = char.Torso
	char.Torso:WaitForChild("ToolGrip").Part1 = location
end)

game.ReplicatedStorage.DisconnectM6D.OnServerEvent:Connect(function(plr)
	
	plr.Character.Torso:WaitForChild("ToolGrip").Part1 = nil
end)

Client Side

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()

local tool = script.Parent.Parent




script.Parent.Parent.Equipped:Connect(function()
	
	char.Humanoid:LoadAnimation(script.Equip):Play()
	
	
	game.ReplicatedStorage.ConnectM6D:FireServer(tool.BodyAttach)
	
	char.Torso:WaitForChild("ToolGrip").Part0 = char.Torso
	char.Torso:WaitForChild("ToolGrip").Part1 = tool.BodyAttach
end)

tool.Unequipped:Connect(function()
	
	char.Humanoid:LoadAnimation(script.Equip):Stop()
	char.Humanoid:LoadAnimation(script.Hold):Stop()
	game.ReplicatedStorage.DisconnectM6D:FireServer()
end)


4 Likes

Motor6ds have Part0 and Part1 properties you have to set to determine what’s being connected by it. You have to set these too.

3 Likes

What you could try doing is waiting for the character to load using the Player.CharacterAdded Event. So when your character loads, you can index the torso no issue for example:

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        local torso = character:WaitForChild(“Torso”)
        local m6d = Instance.new(“Motor6D”, torso)
        m6d.Name = “Name here”
    end)
end)

Edit: Sorry if there are errors, I’m on a phone lol and I fixed a small issue with the Instance.new() (Not declaring the parent)

Edit2: Keep in mind that if it’s r15 then there is a lower and upper torso.

1 Like

I already did that, but new motor6d still not appearing in my Torso when i join

still not appearing motor6d in my Torso oh and btw is R6 so, idk what is causing that instance.new is not working.

Ok now, it works perfectly fine for me using only this code:

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
	    local torso = character:WaitForChild("Torso")
	    local M6D = Instance.new("Motor6D", torso)
	    M6D.Name = "CHEESEMANCOLE"
    end)
end)

image

I try to avoid spoon-feeding but try that code and see.

You are doing this on PlayerAdded when you should be doing this on CharacterAdded. Also, please set the parent last. Setting parent first is bad practice due to the fact that it is bad performance/efficiency-wise.

game.Players.PlayerAdded:Connect(function(plr)          
	plr.CharacterAdded:Connect(function(c)
		local lel = Instance.new("Motor6D")
		lel.Name = "ToolGrip"
		lel.Parent = c.Torso
	end)
end)

Thanks!!! that worked for now, but Motor6D Part0 and Part1 are not setting to bodyattach and torso i am trying to fix it, but thanks!!!

1 Like

The Motor6D’s Part0 and Part1 cannot be set client-side.

Just did that on server and still Part0 and Part1 dont set to torso and bodyattach.