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

Unable to cast Instance to bool,what?

Why does it say this is it because of line 13 and it's loop?If so why and how do I fix it? Output:

22:51:16.693 - Unable to cast Instance to bool 22:51:16.694 - Script 'Workspace.Script', Line 12 - global MakeDisplayArms 22:51:16.694 - Script 'Workspace.Script', Line 28 22:51:16.695 - Stack End 22:51:16.695 - Disconnected event because of exception

game.Players.PlayerAdded:connect(function(Player)
		Player.CharacterAdded:connect(function(Character)
---------------------------------------------------------
			function MakeDisplayArms()
---------------------------------------------------------
				local CurrentCamera = game.Workspace.CurrentCamera
				local PlayerArms = {
					Character["Right Arm"],
					Character["Left Arm"]}
---------------------------------------------------------
					for i,v in pairs (PlayerArms) do
FoundClonedArms = CurrentCamera:FindFirstChild("Cloned",v)--Finds for Cloned parts
				if not FoundClonedArms then--Litte debounce
						local ClonedArms = v:Clone()
						ClonedArms.Parent = CurrentCamera--Hides it from everyone else
						ClonedArms.Name = "Cloned",v--Renames it
						ClonedArms.CanCollide = false
						local Weld = Instance.new("Weld")
							Weld.Part0 = v--Welds it Arms
							Weld.Part1 = ClonedArms
						return ClonedArms
						else
					return FoundClonedArms
					end
				end
			end
---------------------------------------------------------			
			MakeDisplayArms()
		end)
end)

What is this script suppose to do? This script is suppose to make a fake arm that is hidden in the CurrentCamera and that the player can see his arm when zoomed in.

2 answers

The problem is EXACTLY what it says it is. The second argument to findFirstChild() is a BOOL value, v is an INSTANCE.

The CORRECT way to add strings together is by using ".."

Example

local MyString = "Hello "
local player = "Player"

local JoinedString = MyString .. player

print(JoinedString)
--> Hello Player

Your code would be

game.Players.PlayerAdded:connect(function(Player)
        Player.CharacterAdded:connect(function(Character)
---------------------------------------------------------
            function MakeDisplayArms()
---------------------------------------------------------
                local CurrentCamera = game.Workspace.CurrentCamera
                local PlayerArms = {
                    Character["Right Arm"],
                    Character["Left Arm"]}
---------------------------------------------------------
                    for i,v in pairs (PlayerArms) do -- IS V A OBJECT OR A STRING? IF IT IS AN OBJECT, I WOULD USE v.Name
FoundClonedArms = CurrentCamera:FindFirstChild("Cloned_" .. v)--Finds for Cloned parts
                if not FoundClonedArms then--Litte debounce
                        local ClonedArms = v:Clone()
                        ClonedArms.Parent = CurrentCamera--Hides it from everyone else
                        ClonedArms.Name = "Cloned_" .. v--Renames it
                        ClonedArms.CanCollide = false
                        local Weld = Instance.new("Weld")
                            Weld.Part0 = v--Welds it Arms
                            Weld.Part1 = ClonedArms
                        return ClonedArms
                        else
                    return FoundClonedArms
                    end
                end
            end
---------------------------------------------------------           
            MakeDisplayArms()
        end)
end)

Disclaimer: untested code, report future problems.

I see you're trying to concatenate a string, try this.

game.Players.PlayerAdded:connect(function(Player)
        Player.CharacterAdded:connect(function(Character)
---------------------------------------------------------
            function MakeDisplayArms()
---------------------------------------------------------
                local CurrentCamera = game.Workspace.CurrentCamera
                local PlayerArms = {
                    Character["Right Arm"],
                    Character["Left Arm"]}
---------------------------------------------------------
                    for i,v in pairs (PlayerArms) do
FoundClonedArms = CurrentCamera:FindFirstChild("Cloned_"..v.Name)--Finds for Cloned parts
                if not FoundClonedArms then--Litte debounce
                        local ClonedArms = v:Clone()
                        ClonedArms.Parent = CurrentCamera--Hides it from everyone else
                        ClonedArms.Name = "Cloned_"..v.Name --Renames it
                        ClonedArms.CanCollide = false
                        local Weld = Instance.new("Weld")
                            Weld.Part0 = v--Welds it Arms
                            Weld.Part1 = ClonedArms
                        return ClonedArms
                        else
                    return FoundClonedArms
                    end
                end
            end
---------------------------------------------------------           
            MakeDisplayArms()
        end)
end)

More information: http://wiki.roblox.com/index.php?title=Concatenation

2 comments

0

I got a error saying attempt to concatenate local 'v' (a userdata value)

0

Edited script, should work now. I tried to concatenate an instance, when I should've been concatenating a string, which is the name.

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