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

Unable to cast Instance to bool,what?

Asked by 9 years ago

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

Log in to vote
1
Answered by
iaz3 190
9 years ago

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.

Ad
Log in to vote
0
Answered by 9 years ago

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

0
I got a error saying attempt to concatenate local 'v' (a userdata value) kevinnight45 550 — 9y
0
Edited script, should work now. I tried to concatenate an instance, when I should've been concatenating a string, which is the name. Spongocardo 1991 — 9y

Answer this question