Function that is supposed to execute when a RemoteEvent is fired is not working

  1. What do you want to achieve? Keep it simple and clear!

I have a tool which you can grab people with. I want it so that if the player unequips the tool, the values that lets the game know who was grabbed are destroyed, and then the grabbed player is let go.

  1. What is the issue? Include screenshots / videos if possible!

The remote is firing, but the function for when the remote is fired is just not working, even though it looks like it should work.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

At first I used RemoteEvent.OnServerEvent = function(), but then I found out that that OnServerEvent is a event and not a callback. So then I used RemoteEvent.OnServerEvent:connect(function() end), but again, it doesn’t work.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

Local Script:

-- everything for the Grab tool to work is not view in this post as it is not important
script.Parent.Unequipped:connect(function()
	local remote = game.ReplicatedStorage:WaitForChild("disableTool")
	remote:FireServer()
	print("Event Fired!")
end)

Server Script:

local a = Instance.new("RemoteEvent", game.ReplicatedStorage)
a.Name = "disableTool"

function disableTool(plr)
	local personValue = tostring(plr.GrabbedPerson.Value)
	local plr2 = game.Players[personValue]
	if plr and plr2 then
		print("Player1 and Player2 are true.")
		local a = plr:WaitForChild("GrabbedPerson") 
		local b = plr2:WaitForChild("GrabbedBy")
		-- GrabbedPerson and GrabbedBy are the values which make the Grab tool work, if it is removed then the player is let go.
		
		if a.Value == plr2 then
			a:Destroy()
			print("GrabbedPerson was removed!")
		end
		
		if b.Value == plr then
			b:Destroy()
			print("GrabbedBy was removed!")
		end
	end
end

a.OnServerEvent:connect(function(plr, disableTool) end)

I think you need to do

a.OnServerEvent:Connect(function(plr)
    disableTool(plr)
end)
1 Like

Oh, I guess the post I was looking at was outdated or something. :sweat_smile:

For future reference, when you want remote events to directly trigger functions you should do.

RemoteEvent.OnServerEvent:Connect(functionName)

function functionName(ArgumentsSentFromTheRemoteEvent)

1 Like