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

Torso is not a valid member of Model "Workspace.TommyHArden" ?

local UserInputService = game:GetService("UserInputService")

function scanInStorage(placeToScan)
	for _, Object in pairs(placeToScan:GetChildren()) do
		local Plr = game.Players.LocalPlayer
		local Part = Object.Radius
		local Distance = 7
		
		local UI = Object["Display Part"].BillboardGui
		local Split = string.split(Object.Name, "-")
		local Torso = game.Workspace:WaitForChild(Plr.Name, 3).Torso
		
		UI.Frame.Regiment.Text = Split[1]

		if (Torso.Position - Part.Position).Magnitude <= Distance then
				UserInputService.InputBegan:Connect(
					function(Input, GameProcessedEvent)
						if Input.UserInputType == Enum.UserInputType.Keyboard then
							if Input.KeyCode == Enum.KeyCode.E then
								local Remote = game.ReplicatedStorage.Remotes.equipUniform

								local Shirt = Object.Shirt.ShirtTemplate
								local Pants = Object.Pants.PantsTemplate

								wait()
								Remote:FireServer(Plr, Shirt, Pants)
							end
						end
					end)
				
			
			end
	end
end
scanInStorage(game.Workspace.UniformHolder)

https://gyazo.com/ab7066fe6edafba25db3877e1a4e0bf7 https://gyazo.com/05e3383815435ff41c06801148e5f15a https://gyazo.com/6ff9819e505e46dfbbabc10f19a3ff4e

error on line 11

1 answer

✓ Accepted answer

Easy fix.

There are 2 ways of doing this.

You could:

A) Wait for the torso:

local UserInputService = game:service("UserInputService")

function scanInStorage(placeToScan)
    for _, Object in pairs(placeToScan:GetChildren()) do
        local Plr = game.Players.LocalPlayer
        local Part = Object.Radius
        local Distance = 7

        local UI = Object["Display Part"].BillboardGui
        local Split = string.split(Object.Name, "-")
        local Torso = Plr.Character:WaitForChild('Torso')

        UI.Frame.Regiment.Text = Split[1]

        if (Torso.Position - Part.Position).Magnitude <= Distance then
                UserInputService.InputBegan:Connect(
                    function(Input, GameProcessedEvent)
                        if Input.UserInputType == Enum.UserInputType.Keyboard then
                            if Input.KeyCode == Enum.KeyCode.E then
                                local Remote = game.ReplicatedStorage.Remotes.equipUniform

                                local Shirt = Object.Shirt.ShirtTemplate
                                local Pants = Object.Pants.PantsTemplate

                                wait()
                                Remote:FireServer(Plr, Shirt, Pants)
                            end
                        end
                    end)


            end
    end
end
scanInStorage(game.Workspace.UniformHolder)

B) Use a repeat loop:

local UserInputService = game:service("UserInputService")

function scanInStorage(placeToScan)
    for _, Object in pairs(placeToScan:GetChildren()) do
        local Plr = game.Players.LocalPlayer
        local Part = Object.Radius
        local Distance = 7

        local UI = Object["Display Part"].BillboardGui
        local Split = string.split(Object.Name, "-")
	repeat wait() until Plr.Character:FindFirstChild('Torso')
        local Torso = Plr.Character.Torso
        UI.Frame.Regiment.Text = Split[1]

        if (Torso.Position - Part.Position).Magnitude <= Distance then
                UserInputService.InputBegan:Connect(
                    function(Input, GameProcessedEvent)
                        if Input.UserInputType == Enum.UserInputType.Keyboard then
                            if Input.KeyCode == Enum.KeyCode.E then
                                local Remote = game.ReplicatedStorage.Remotes.equipUniform

                                local Shirt = Object.Shirt.ShirtTemplate
                                local Pants = Object.Pants.PantsTemplate

                                wait()
                                Remote:FireServer(Plr, Shirt, Pants)
                            end
                        end
                    end)


            end
    end
end
scanInStorage(game.Workspace.UniformHolder)

2 comments

0

I used B, thanks for the help! (:

0

np

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