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

May I have some assistance with a RemoteFunction?

So, my script is finding out which flavour has been clicked on a GUI and then send the name of that flavour to the server. I have the function in the LocalScript and I'm trying to send it to the script, but I can't seem the figure out how. Here is my code that I have tried but hasn't seem to work. (I'm new to using RemoteFunctions).

Code:

--Local Script

local crispFlavour = game.ReplicatedStorage.crispFlavour
local frame = script.Parent
local tool = game.ReplicatedStorage.Crisps

local function getFlavour(player, flavour)
	for i,v in pairs(frame:GetChildren()) do
		game.Workspace.Bowl.ClickDetector.MouseClick:Connect(function(player)
			v.MouseButton1Click:Connect(function()
				local flavour = v
				for i,v in pairs(tool:GetChildren()) do
					if v.Name == flavour.Name then
						crispFlavour:FireServer(flavour)
					end
				end
			end)
		end)
	end
end

--Server Script

local crispFlavour = game.ReplicatedStorage.crispFlavour

local newPart = crispFlavour:InvokeServer(flavour)
print(flavour)
--I'm pretty sure this is where the problem is.

Any help would be much appreciated, thank you.

1 answer

✓ Accepted answer

You need to check on the server when the event is being fired.

Your code on line 14 fires the server vvvv

crispFlavour:FireServer(flavour)
--since it is a remote function, it needs to be:
crispFlavour:InvokeServer()

To see when the remote is being fired, you need to put this into your server script:

local function printFlavour(player, flavour)
	print(player.Name, "sent the flavour ", flavour)
end
 
nameOfEventGoesHere.OnServerInvoke = printFlavour

Also, someone else answered the post saying that you're passing in flavour instead of flavours name so you need to send flavour.Name instead. Keen eye because I did not catch that.

3 comments

0

Aight, got it.

0

Also, needs to be InvokeServer() not FireServer

0

If you're using a remote event it is fireServer() and .OnServerEvent:Connect(printFlavour) instead of what I have on line 5

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