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

Unable to cast Instance to CoordinateFrame?

Asked by 4 years ago

I made a model and I am trying to position it on the player. I don't how to fix this error I keep on getting this error that says

Unable to cast Instance to CoordinateFrame

I don't know what it is. Here is my script I don't know what I am doing wrong.

local Lighting = game.Lighting
local Vest = Lighting:WaitForChild("Flak Jacket")


game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:connect(function(character)
        character:WaitForChild("UpperTorso")

        local ClonedVest = Vest:Clone()
        ClonedVest.Parent = character

        ClonedVest:SetPrimaryPartCFrame(character:WaitForChild("UpperTorso"))

        local Weld = Instance.new("Weld")
        Weld.Part0 = ClonedVest.Main
        Weld.Part1 = character:WaitForChild("UpperTorso")
        Weld.Parent = character:WaitForChild("UpperTorso")
        ClonedVest:SetPrimaryPartCFrame(ClonedVest:GetPrimaryPartCFrame() * CFrame.new(0,0,5))
    end)
end)
0
The error puts in on line 12 Fxding_cam 60 — 4y
2
you forgot to put a .CFrame after character:WaitForChild("UpperTorso") kisty1 111 — 4y

1 answer

Log in to vote
1
Answered by
iuclds 720 Moderation Voter
4 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your answer.

You forgot to define the cframe

local Lighting = game.Lighting
local Vest = Lighting:WaitForChild("Flak Jacket")


game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:connect(function(character)
        character:WaitForChild("UpperTorso")

        local ClonedVest = Vest:Clone()
        ClonedVest.Parent = character

        ClonedVest:SetPrimaryPartCFrame(character:WaitForChild("UpperTorso").CFrame)

        local Weld = Instance.new("Weld")
        Weld.Part0 = ClonedVest.Main
        Weld.Part1 = character:WaitForChild("UpperTorso")
        Weld.Parent = character:WaitForChild("UpperTorso")
        ClonedVest:SetPrimaryPartCFrame(ClonedVest:GetPrimaryPartCFrame() * CFrame.new(0,0,5))
    end)
end)
Ad

Answer this question