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

Why do I get this "Bad cast" error in my script even thought everything seems fine?

Asked by 5 years ago
Edited 5 years ago

Alright, so I made a script.. that creates a rope that attaches to the player and a part when you click on the part. However, when I click on the part it says an annoying error, "bad cast".

I made this script before but My game decided to crash and I lost everything I made.. I made a new script but now it wont work. Why?

local wa = game.Workspace.WebAttachment
local plr = game.Players.LocalPlayer
local char = plr.Character


local uis = game:GetService("UserInputService")



uis.InputBegan:Connect(function(input, gameProcessed)
        if input.UserInputType == Enum.UserInputType.MouseButton1 then

        local attachmentA = Instance.new("Attachment", wa)
        attachmentA.Position = Vector3.new(input.Position)

        local head = char:FindFirstChild("Head")
        local atatchmentB = Instance.new("Attachment", head)
        atatchmentB.Position = Vector3.new(0,.5,0)

        local web = Instance.new("RopeConstraint", wa)
        web.Attachment0 = wa  --Not sure if the error is here but everytime I click on "bad cast" it brings me to this line.
        web.Attachment1 = head
                web.Length = 50
                web.Color = BrickColor.New("Red")
                web.Visible = True
    end
end)

1 answer

Log in to vote
1
Answered by
552557 20
5 years ago

"true" is spelt wrong. A part is not an attachment instance.

local wa = game.Workspace.WebAttachment
local plr = game.Players.LocalPlayer
local char = plr.Character


local uis = game:GetService("UserInputService")



uis.InputBegan:Connect(function(input, gameProcessed)
        if input.UserInputType == Enum.UserInputType.MouseButton1 then

        local attachmentA = Instance.new("Attachment", wa)
        attachmentA.Position = Vector3.new(input.Position)

        local head = char:FindFirstChild("Head")
        local attachmentB = Instance.new("Attachment", head)
        attachmentB.Position = Vector3.new(0,.5,0)

        local web = Instance.new("RopeConstraint", wa)
        web.Attachment0 = wa
        web.Attachment1 = attachmentB
                web.Length = 50
                web.Color = BrickColor.New("Red")
                web.Visible = true
    end
end)

Ad

Answer this question