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

why isn't my remote function returning a bool?

Asked by 4 years ago
Edited 4 years ago

for some reason the server wont return a bool value or maybe the client isn't picking it up, please help. Btw i have left the rest of the code out because it is unnecessary and is hard to read.

Client:

Uis.InputBegan:Connect(function(inputObject)
    if inputObject.KeyCode == Enum.KeyCode.E then
        if mouse.Target ~= nil then 
            part = mouse.Target
            part = part:FindFirstAncestorWhichIsA("Model")
            if part then
                local ig = reqGrab:InvokeServer(part) -- the remote function
                if ig == true then -- the problem
                    print(123456)
                    isGrabbing = true
                end
            end
        end
    end
end)

Server:

function requestGrab(player, part)
    if playerParts[part] ~= nil then return false end -- will not let code run if part is associated with a player, 
    if collectionService:HasTag(part, tag) then
        local primaryPart = part:FindFirstChild("PrimaryPart")
        if primaryPart then
            playerParts[part] = player
            applyConfig(part)
            for i, v in pairs(part:GetChildren()) do
                v:SetNetworkOwner(player)
            end
            print(part.Name .. " Successfully claimed!")
            return true -- i want this value to be returned to the client side      
        end
    end
end
0
any output? VitroxVox 884 — 4y
0
nope no errors and the print doesn't run Code1400 75 — 4y
0
it is equal to nil Code1400 75 — 4y

1 answer

Log in to vote
2
Answered by 4 years ago

I don't think you can search the primary part using :FindFirstChild(), thats why the findfirstchild will return nil and inside it is the return so without the primary part == true, it will return nil, and also mouse.Target can only get parts, I don't think it can get models or tools, try

if part.Parent:IsA("Model")
    local primaryPart = part.Parent.PrimaryPart
    if primaryPart then
        -- Your code
    end
end

0
i found the solution to the problem, i forgot i was calling the function from another function and returning the bool only returned it to the function it was in. and i named one of the parts in the model primary part, im not actually referencing the primarypart property of a model, and the variable part is changed in the next line to the parent "Model". ill accept your answer Code1400 75 — 4y
Ad

Answer this question