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

Why are none of my Locals working? There's a red line under NewPart on line 8.

Here's the code:

local plr = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
	local NewPart = Instance.new("Part", game.Workspace)
	local plrName = game.Players.LocalPlayer.Name
	local WorkspaceCharacter = game.Workspace:WaitForChild(plrName)
	local CharacterLeftFoot = WorksaceCharacter.LeftFoot
		local WorkspaceCharacterPosition = CharacterLeftFoot(Vector3(CharacterLeftFoot.X, CharacterLeftFoot.Y, CharacterLeftFoot.Z)
	NewPart.Position = Vector3.new(WorkspaceCharacterPosition
	
	end)

1 answer

✓ Accepted answer

The problem you are having is a simple typo, but there are a few other things you need to know:

--in a local script, instantiate all unchanging variables outside of functions
local localPlayer = game.Players.LocalPlayer
local character = localPlayer.Character
local charPos = character.HumanoidRootPart.CFrame.Position
-- why set the left foot of the character or the player name to a variable if you never use it?

script.Parent.MouseButton1Click:Connect(function()
    local NewPart = Instance.new("Part")--second arg is deprecated
    NewPart.Position = Vector3.new(charPos)--don't forget to close your functions
    NewPart.Parent = workspace --set the parent after setting all of the other properties of the new part
end)

So I explained everything in comments, but also don't forget to keep your indentations neat for you to keep your scripts clearly readable. As for your initial question, locals never break unless you don't follow variable naming rules. And since this answers your question, don't forget to mark it as answered.

3 comments

0

it says "HumanoidRootPart is not a valid member of Model" so how do i fix

0

Sorry, I was under the impression that you were using a default character.

0

You should change that to whatever part is closest to the center of your custom character.

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