Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

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

Asked by 9 years ago

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

01part = Instance.new("Part",game.Workspace)
02local players = game.Players.LocalPlayer
03local mouse = players:GetMouse()
04 
05mouse.KeyDown:connect(function(key) if key == "e" then part.CFrame = CFrame.new(players.Head.Position) + Vector3.new(0,5,0)
06part.Anchored = true
07local new = Instance.new("Part",game.Workspace)
08new.CFrame = CFrame.new(players.Head.Position) + Vector3.new(0,5,0)
09new.Anchored = true
10end end)

1 answer

Log in to vote
1
Answered by
Pyrondon 2089 Game Jam Winner Moderation Voter Community Moderator
9 years ago

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

This should work, I think:

01part = Instance.new("Part",game.Workspace)
02local players = game.Players.LocalPlayer
03local Character = players.Character
04local mouse = players:GetMouse()
05 
06mouse.KeyDown:connect(function(key) if key == "e" then part.CFrame = CFrame.new(players.Character.Head.Position) + Vector3.new(0,5,0)
07part.Anchored = true
08local new = Instance.new("Part",game.Workspace)
09new.CFrame = CFrame.new(players.Character.Head.Position) + Vector3.new(0,5,0)
10new.Anchored = true
11end
12end)
Ad

Answer this question