Moving item above players head on changed event

When a Boolean value turns true an clone of an object spawns right above a player’s head.
The error I get is CFrame expected, got instance from PartCopy.Position = (player.Character.HumanoidRootPart*CFrame.new(0,6,0)).PartCopy

Or the error attempt to call CFrame value from PartCopy.Position = (player.Character.HumanoidRootPart.Position + PartCopy.CFrame(0,6,0))

local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local Turn = PlayerVars.Turn
local Part = ReplicatedStorage.Part

Turn.Changed:Connect(function()
    if Turn.Value == true then
        local PartCopy = Part:Clone()
        local PartCopy = Instance.new("Part",workspace)
	--PartCopy.Position = (player.Character.HumanoidRootPart*CFrame.new(0,6,0)).PartCopy
	PartCopy.Position = (player.Character.HumanoidRootPart.Position + PartCopy.CFrame(0,6,0))
    end
end)

How can I correctly get the part to go over the player’s head?

You don’t need to create a new instance for a cloned one. If you declare a variable which stores a :Clone()'d instance, then that variable can be used as it won’t store the original item.

You are also attempting to mix Vector3 with CFrame. Attempt to use player.Character.HumanoidRootPart.Position + Vector3.new(0,6,0)

1 Like

You’re supposed to index the CFrame with a constructor, you can’t just have it like CFrame(0,6,0)

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Turn = PlayerVars.Turn
local Part = ReplicatedStorage.Part

Turn.Changed:Connect(function(CurrentValue)
    if CurrentValue == true then
        local PartCopy = Part:Clone()
        PartCopy.Parent = workspace
    	--PartCopy.Position = (player.Character.HumanoidRootPart*CFrame.new(0,6,0)).PartCopy
	    PartCopy.CFrame = player.Character.HumanoidRootPart.CFrame * CFrame.new(0, 6, 0)
    end
end)

Also, you can reference the parameter provided by the Changed event, you don’t have to do if Turn.Value == true

2 Likes