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

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

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:

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)
Ad

Answer this question