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

Placing a part on the character's head?

Asked by 6 years ago

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)

1 answer

Log in to vote
0
Answered by
SteamG00B 1633 Moderation Voter
6 years ago
Edited 6 years ago

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.

0
Thank you for the help! top500widowxd 23 — 6y
Ad

Answer this question