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

Prop Name Returning Nil?

Asked by 9 years ago

Hello, I am making somewhat of a prop hunt game, and I keep getting tripped up at this one step. I try to return the name of the object to turn into, but it does not work. The error is in line 8, but nothing it the output says it is wrong.

Script:

function scanForProp(place, propNeeded)
    for i,v in pairs(place) do
        if v.Name == "Prop" then
            local propName = v:FindFirstChild'PropName'
            print(propName.Value)
            if propName.Value == propNeeded then
                return propName.Value --This returns nil
            end
        end
    end
end

function checkPlayerForProps(char)
    function checkPlayerForProps(char)
    for i,z in pairs(char:GetChildren()) do
        if z.Name == "Prop" then
            z:Destroy()
        end
    end
end

function createProp(char, propName)
    local charP = char
    if charP then
        for i,v in pairs(charP:GetChildren()) do 
            if v:IsA("Part") then v.Transparency = 1 
            elseif v:IsA("Hat") then v.Handle.Transparency = 1 
            elseif v.Parent.Head:FindFirstChild("face") then 
            v.Parent.Head.face.Transparency = 1 
            end
        end
    end
    for i,s in pairs(game.workspace:GetChildren()) do
        if s.Name == "Prop" then
            local y = s:FindFirstChild'PropName'
            if y.Value == propName then
                print(y.Value)
                local newProp = y.Parent:Clone()            
                newProp.Parent = char
                newProp:FindFirstChild'PropMaster':Destroy()
                local weld1 = Instance.new("Weld", newProp)
                weld1.Part0 = newProp weld1.Part1 = char:findFirstChild("Torso")    
            end         
        end     
    end     
end     
end


function ListenToCommand(action, player, prop)
    if action == "BecomeProp" then
        local gamePlayer = game.Players:FindFirstChild(player.Name)
        local char = gamePlayer.Character
        local x = scanForProp(game.workspace:GetChildren(), prop)
        local animator = char.Humanoid:FindFirstChild'Animator' 
        --[[if animator then 
            animator:Destroy()          
        else
            print'Not Found'
         end--]]
        checkPlayerForProps(char)
        createProp(char, x) 
    end         
end

local cmd = game.workspace.PropCommand
cmd.Event:connect(function(action, player)
    ListenToCommand(action, player)
end)

Answer this question