I'm trying to make a script that creates a part when the "R" key is pressed.
Everything works fine except that the part's position would not go on top of the character's head.
local baseplate = workspace.Baseplate local player = game.Players.LocalPlayer local character = player.Character if not character or character.Parent then character = player.CharacterAdded:wait() print(character) end local function Fire(actionName, inputState, inputObject) if inputState == Enum.UserInputState.Begin then local part = Instance.new("Part") part.Parent = workspace print(character) part.Position = Vector3.new(character.Head) -- How can you also add an offset so the part is 10 units above the character's head? end end game.ContextActionService:BindAction("ChangeColor", Fire, false, Enum.KeyCode.R)
You should use CFrames, so your script would be:
local baseplate = workspace.Baseplate local player = game.Players.LocalPlayer local character = player.Character if not character or character.Parent then character = player.CharacterAdded:wait() print(character) end local function Fire(actionName, inputState, inputObject) if inputState == Enum.UserInputState.Begin then local part = Instance.new("Part") part.Parent = workspace print(character) part.CFrame = character.Head.CFrame+Vector3.new(0,10,0)--this is the only thing that is changed end end game.ContextActionService:BindAction("ChangeColor", Fire, false, Enum.KeyCode.R)
it would place it 10 studs above the player's head.