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

why isn't my remote function returning a bool?

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

3 comments

0

any output?

0

nope no errors and the print doesn't run

0

it is equal to nil

1 answer

✓ Accepted answer

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

1 comment

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

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