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

Why doesn't this make a part appear over my head?

This script is a local script inside starterpack, I think the problem is I need to get the character in workspace, but I don't know how to do that.
I would like this to make the part appear over anyone no matter the name, that's why I did LocalPlayer

When I press E, this error comes up Head is not a valid member of Player

part = Instance.new("Part",game.Workspace)
local players = game.Players.LocalPlayer
local mouse = players:GetMouse()

mouse.KeyDown:connect(function(key) if key == "e" then part.CFrame = CFrame.new(players.Head.Position) + Vector3.new(0,5,0)
part.Anchored = true 
local new = Instance.new("Part",game.Workspace)
new.CFrame = CFrame.new(players.Head.Position) + Vector3.new(0,5,0)
new.Anchored = true
end end)

1 answer

✓ Accepted answer

The output is correct -- Head isn't a valid member of player; it's under Character, instead.

This should work, I think:

part = Instance.new("Part",game.Workspace)
local players = game.Players.LocalPlayer
local Character = players.Character
local mouse = players:GetMouse()

mouse.KeyDown:connect(function(key) if key == "e" then part.CFrame = CFrame.new(players.Character.Head.Position) + Vector3.new(0,5,0)
part.Anchored = true 
local new = Instance.new("Part",game.Workspace)
new.CFrame = CFrame.new(players.Character.Head.Position) + Vector3.new(0,5,0)
new.Anchored = true
end 
end)

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