Trouble invoking server with arg

  1. What do you want to achieve?
    I would like to successfully invoke the server with the target variable.

  2. What is the issue?
    When the function is triggered, an error message is sent in the output, which reads: attempt to call boolean value at line 22. I put bold syntax around the problematic line.

  3. What solutions have you tried so far?
    I have tried revising the function, such as invoking the remote on the next line however the same error message was sent.

-- Fl_ured
-- Grab Client
-- March 22, 2020


local tagName = "Pickups"

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

local inputService = game:GetService("UserInputService")
local collectionService = game:GetService("CollectionService")

local stopGrab = game.ReplicatedStorage.StopGrab
local requestGrab = game.ReplicatedStorage.RequestGrab

local trackingPart = nil
local heartbeat

function updateTrackingPart()
	local ray = mouse.UnitRay
	ray = Ray.new(ray.Origin, ray.Direction * 20)
	local position = ray.Origin + (ray.Direction * 20)
	trackingPart.BodyPosition = position
end

function MouseUp()
	if (not trackingPart) then return end
	stopGrab:FireServer(trackingPart)
	trackingPart =  nil
	heartbeat:Disconnect()
end

function MouseDown()
	local target = mouse.Target
**     if (target and requestGrab:InvokeServer(target)) then
		trackingPart = target
		heartbeat = game:GetService("RunService").Heartbeat:Connect(updateTrackingPart)
	end
end

function CharacterAdded(character)
	mouse.TargetFilter = character
end


inputService.InputBegan:Connect(function(object,processed)
	if (processed) then return end
	if (object.UserInputType == Enum.UserInputType.MouseButton1) then
		MouseDown()
	end
end)

inputService.InputEnded:Connect(function(object,processed)
	if (object.UserInputType == Enum.UserInputType.MouseButton1) then
		MouseUp()
	end
end)

CharacterAdded(player.Character or player.CharacterAdded:Wait())
player.CharacterAdded:Connect(CharacterAdded)

Where is the code that is run on the server for the requestGrab remote event?
Did you get any other errors?

No, that was the only error I recieved. RequestGrab is a RemoteFunction, my apologies for not clarifying.

-- Fl_ured
-- GrabHandle
-- March 22, 2020

local tagName = "Pickups"

local collectionService = game:GetService("CollectionService")

local parts = collectionService:GetTagged(tagName)

local playerParts = {}

local rng = Random.new()
for _,part in pairs(parts) do
	part.Size = Vector3.new(rng:NextNumber(3,7), rng:NextNumber(3,7), rng:NextNumber(3,7))
	part.Color = Color3.new(rng:NextNumber(2,5), rng:NextNumber(2,5), rng:NextNumber(2,5))
	part.Anchored = true
	part.CanCollide = true
	local bodyPosition = Instance.new("BodyPosition")
	local bodyGyro = Instance.new("BodyGyro")
	bodyPosition.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
	bodyGyro.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
	bodyPosition.Parent = part
	bodyGyro.Parent = part
end

function RequestGrab(player, part)
	if playerParts[player] then return false end
	if (not collectionService:HasTag(part, tagName) or not part.Anchored) then
		return false
	end
	part.Anchored = false
	part:SetNetworkOwner(player)
	return true
end

function StopGrab(player,part)
	if (playerParts[player] ~= part) then return false end
	playerParts[player] = nil
	part.Anchored = true
	part:SetNetworkOwnershipAuto()
end

game.ReplicatedStorage.RequestGrab.OnServerInvoke = RequestGrab()
game.ReplicatedStorage.StopGrab.OnServerEvent:Connect(StopGrab)

game.Players.PlayerRemoving:Connect(function(player)
	if (playerParts[player]) then
		StopGrab(player, playerParts[player])
	end
end)

I see the issue.
On this line

game.ReplicatedStorage.RequestGrab.OnServerInvoke = RequestGrab()

get rid of the ()
so:

game.ReplicatedStorage.RequestGrab.OnServerInvoke = RequestGrab

setting the OnServerInvoke to RequestGrab() basically set it to a boolean value, so when you went to call the function, it was actually calling the boolean value, not the function instelf.

6 Likes

Thank you. I was up late last night, can’t believe I overlooked that.

1 Like