RemoteFunction not firing and breaking script

So I’m trying to make this local script which allows you to buy weapons from a shop GUI via RemoteFunctions. This local script works fine until the “buy portion” of the script, where it fails to fire a RemoteFunction.

Now the odd thing is, the local script I am using for the RemoteFunction is a complete carbon copy of one I used in a completely different shop, which I specifically designed to be modular (essentially you can copy it into other shops using a similiar GUI and it will know exactly what to do). Which is what makes it weird.

Here's a short snippet from the local script:

– *** NOTE: I HAVE HID THE VARIABLES TO SIMPLIFY THE SCRIPT SO IT’S EASIER TO READ ***

success = nil
if selectedItem.Value ~= nil then -- (THIS HAS A VALUE)
	success = RSFolder.CheckSale:InvokeServer(selectedItem.Value) -- script doesn't know what to do here and breaks as a result

	print ("this doesn't print") -- This doesn't print out
end
And the full script...
local replicatedStorage = game:GetService("ReplicatedStorage")
local RSFolder = replicatedStorage:WaitForChild(script.Parent.Parent.Parent.Name)
local selectedItem = script.Parent.Parent.Parent:WaitForChild("SelectedItem")

local greenBackground = Color3.fromRGB(2, 234, 111)
local greenBorder =  Color3.fromRGB(7, 53, 28)

local redBackground = Color3.fromHSV(234, 34, 2)
local redBorder = Color3.fromHSV(53, 28, 7)

local timeDelay = 2
local success

local canClick = true

-- Limitations

local Max = 5

local Starterpack = game.StarterPack
local Backpack = game.Players.LocalPlayer.Backpack
local Owned = script.Parent.Parent.Owned.Value
local Equipped = script.Parent.Parent.Equipped.Value

if Owned == true then

	local Equipped = script.Parent.Parent.Equipped

	if Equipped.Value == true then

		script.Parent.Text = "Unequip"

	else

		script.Parent.Text = "Equip"

	end
end

-- SOUNDS

local GUI = script.Parent.Parent.Parent.Parent

local Purchase = GUI.GUISounds.Purchased
local Equip = GUI.GUISounds.Equip
local Fail = GUI.GUISounds.Fail

local Both = game.ReplicatedStorage.Saving.Both

script.Parent.MouseButton1Click:Connect(function()

	if canClick == true then

		Both:FireServer()

		-- OWNS ITEM

		if Owned == true then

			-- IF THE ITEM ISN'T EQUIPPED

			if Equipped == false then

				-- INVENTORY FULL

				local equipsuccess = nil
				if selectedItem.Value ~= nil then
					equipsuccess = RSFolder.CheckSale:InvokeServer(selectedItem.Value)
				end

				if #Backpack:GetChildren() > 5 then

					if Equipped == true then

						Fail:Play()
						RSFolder.Equip:InvokeServer(Equipped)
						script.Parent.Text = ("Unequipped!")
						canClick = false
						script.Parent.BackgroundColor3 = greenBackground
						script.Parent.BorderColor3 = greenBorder
						script.Parent.TextColor3 = greenBorder

						wait(timeDelay)

						script.Parent.Text = ("Equip")

						canClick = true

					else

						Equip:Play()
						script.Parent.Text = ("Inventory Full!")
						canClick = false
						script.Parent.BackgroundColor3 = greenBackground
						script.Parent.BorderColor3 = greenBorder
						script.Parent.TextColor3 = greenBorder

						wait(timeDelay)

						script.Parent.Text = ("Unequip")

						canClick = true
					end

					-- INVENTORY NOT FULL

				else

					if Equipped == true then

						Equip:Play()
						RSFolder.Equip:InvokeServer(Equipped)
						script.Parent.Text = ("Equipped!")
						canClick = false
						script.Parent.BackgroundColor3 = greenBackground
						script.Parent.BorderColor3 = greenBorder
						script.Parent.TextColor3 = greenBorder

						wait(timeDelay)

						script.Parent.Text = ("Unequip")

						canClick = true

					else
						Equip:Play()
						RSFolder.Equip:InvokeServer(Equipped)
						script.Parent.Text = ("Unequipped!")
						canClick = false
						script.Parent.BackgroundColor3 = greenBackground
						script.Parent.BorderColor3 = greenBorder
						script.Parent.TextColor3 = greenBorder

						wait(timeDelay)

						script.Parent.Text = ("Equip")

						canClick = true
					end

				end
			end

			-- IF THE ITEM ISN'T OWNED			

		else

			success = nil -- *** BUY PORTION BEGINS ***
			if selectedItem.Value ~= nil then
				success = RSFolder.CheckSale:InvokeServer(selectedItem.Value)
				
				print ("this doesn't print")
			end -- *** BUY PORTION ENDS***

			-- CAN AFFORD ITEM

			if success then

				Purchase:Play()
				canClick = false
				script.Parent.BackgroundColor3 = greenBackground
				script.Parent.BorderColor3 = greenBorder
				script.Parent.TextColor3 = greenBorder

				script.Parent.Text = ("Purchased!")

				Owned = true
				wait(timeDelay)

				script.Parent.Text = ("Equip")
				canClick = true


				-- CAN'T AFFORD ITEM

			else

				Fail:Play()
				canClick = false
				script.Parent.BackgroundColor3 = redBackground
				script.Parent.BorderColor3 = redBorder
				script.Parent.TextColor3 = redBorder
				script.Parent.Text = ("Can't Afford!")
				Owned = false

				wait (timeDelay)

				canClick = true
				script.Parent.BackgroundColor3 = greenBackground
				script.Parent.BorderColor3 = greenBorder
				script.Parent.TextColor3 = greenBorder

				script.Parent.Text = ("Buy")
			end
		end
	end
end)

What makes it even MORE weird, is the fact that I get absolutely no errors or warning in the output AT ALL, so I am essentially trying to repair this completely blindly.

What I would like to know is why this problem is occuring (for ONLY this script), and how I can attempt to repair it.

Why don’t you use RemoteEvent instead of RemoteFunction ?

LocalScript:

game.ReplicatedStorage.RemoteEvent:FireServer(data) --send any data

Server Script:

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player, data. . .)
    --do stuff here with data or anything
end)

Maybe it can fix your problems. Anyways, let me know results.

2 Likes

I’m using a remote function because something is supposed to get relayed back to the player, also the server script isn’t the problem, it’s just the local script

1 Like

Have you made sure that the server script is actually returning something for the remote function? It seems like it’s waiting for something back.

1 Like

Alright so I know it’s not a Server Script problem because this will not run:

RSbin.CheckSale.OnServerInvoke = function(player,item)
	
	print ("coolhouse") -- doesn't print
	
	local toolBP = player.Backpack:FindFirstChild(item)
	local toolInventory = player.Inventory:FindFirstChild(item)

-- (script keeps going)

Check if selectedItem.Value isn’t nil by adding a print.

if selectedItem.Value ~= nil then -- (THIS HAS A VALUE)
	print(selectedItem.Value)
	success = RSFolder.CheckSale:InvokeServer(selectedItem.Value) -- script doesn't know what to do here and breaks as a result

It’s got a value and it prints out completely fine

Totally stumped. Make sure that RSFolder.CheckSale is an actual valid item. You can check this by doing print(RSFolder.CheckSale) and seeing what it returns.

1 Like

that prints too… Also an update:

I made a complete copy of a modular version of the GUI, made the names agree and readded all the weapons and stuff, and it still didn’t work

Make it a RemoteEvent. You can just use another remote event to communicate the data back to the client. RemoteFunctions are too complicated and can throw some weird errors some times and randomly not work.

1 Like

So allegedly .OnClientEvent isn’t a valid member of a RemoteEvent

Updated script snippet
if selectedItem.Value ~= nil then
	RSFolder.CheckSale:FireServer(selectedItem.Value)
				
	RSFolder.Success.OnClientEvent = function() -- OnClientEvent is not a valid member of RemoteEvent "ReplicatedStorage.Blacksmith.Success" (With "Success" being the remote event)
					
		success = true
					
	end
				
	RSFolder.Fail.OnClientEvent = function()
					
		-- do nothing
					
	end
end

This documentation will help you out a bit.

1 Like

It’s meant to be :Connect() not a operation, haha. Also you can’t return information with a RemoteEvent.

1 Like

I know, that’s why I made two remote events

image
That needs to be,

OnClientEvent:Connect(function()

end)

Also, what are you trying to do?

1 Like

I’m trying to make it so the game sees if you can or can’t afford the item, and tells you in the shop gui if you can’t

Still doesn’t work, this is what my script looks like right now

Local script
if selectedItem.Value ~= nil then

	RSFolder.CheckSale:FireServer(selectedItem.Value)
				
	RSFolder.Success.OnClientEvent:Connect(function()
					
		success = true

	end)
-- ...
Server Script
RSbin.CheckSale.OnServerEvent:Connect(function(player,item)
	
	print ("Cool") -- Doesn't print
	
	local toolBP = player.Backpack:FindFirstChild(item)
	local toolInventory = player.Inventory:FindFirstChild(item)
-- ...
Game Explorer

image

1 Like

Huh. Interesting, I’m not sure what the issue is here. Lemme investigate it a little bit to see the issue.

1 Like