Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

May I have some assistance with a RemoteFunction?

Asked by 5 years ago

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

Log in to vote
1
Answered by
royaltoe 5144 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

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.

0
Aight, got it. RyanTheLion911 195 — 5y
0
Also, needs to be InvokeServer() not FireServer royaltoe 5144 — 5y
0
If you're using a remote event it is fireServer() and .OnServerEvent:Connect(printFlavour) instead of what I have on line 5 royaltoe 5144 — 5y
Ad

Answer this question