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
01 | part = Instance.new( "Part" ,game.Workspace) |
02 | local players = game.Players.LocalPlayer |
03 | local mouse = players:GetMouse() |
04 |
05 | mouse.KeyDown:connect( function (key) if key = = "e" then part.CFrame = CFrame.new(players.Head.Position) + Vector 3. new( 0 , 5 , 0 ) |
06 | part.Anchored = true |
07 | local new = Instance.new( "Part" ,game.Workspace) |
08 | new.CFrame = CFrame.new(players.Head.Position) + Vector 3. new( 0 , 5 , 0 ) |
09 | new.Anchored = true |
10 | end end ) |
The output is correct -- Head isn't a valid member of player; it's under Character, instead.
This should work, I think:
01 | part = Instance.new( "Part" ,game.Workspace) |
02 | local players = game.Players.LocalPlayer |
03 | local Character = players.Character |
04 | local mouse = players:GetMouse() |
05 |
06 | mouse.KeyDown:connect( function (key) if key = = "e" then part.CFrame = CFrame.new(players.Character.Head.Position) + Vector 3. new( 0 , 5 , 0 ) |
07 | part.Anchored = true |
08 | local new = Instance.new( "Part" ,game.Workspace) |
09 | new.CFrame = CFrame.new(players.Character.Head.Position) + Vector 3. new( 0 , 5 , 0 ) |
10 | new.Anchored = true |
11 | end |
12 | end ) |