Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

"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)

This discussion is preserved as it was. New answers, comments, and votes are closed.