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

Remote function giving a weird error?

Asked by 4 years ago
Edited 4 years ago

This is my first time using remote functions and I'm very confused. I'm trying to make a mod panel for my game in which you can set a player's speed.

My script:

01local DSS = game:GetService("DataStoreService")
02local SpeedStore = DSS:GetDataStore("SpeedStore")
03 
04game.ReplicatedStorage.ModPanelRemoteFunction.OnServerInvoke:Connect(function(sender, player, value, _type) -- Where the error is
05    if sender:GetRankInGroup(6323488) >= 2 then
06        if _type then
07            if _type == "Name" then
08                game.Players:FindFirstChild(player):WaitForChild("leaderstats"):WaitForChild("Speed").Value = value
09                return true
10            elseif _type == "Id" then
11                game.Players:GetPlayerByUserId(player):WaitForChild("leaderstats"):WaitForChild("Speed").Value = value
12                return true
13            end
14        elseif not _type then
15            local key = player
View all 35 lines...

My local script:

01local playerGui = game.Players.LocalPlayer:WaitForChild("PlayerGui")
02local playerText = playerGui.ModPanel.MainFrame.NameOrUserId.Text
03local newValue = playerGui.ModPanel.MainFrame.NewValue.Text
04 
05script.Parent.MouseButton1Click:Connect(function()
06    if game.Players:FindFirstChild(playerText) then
07        local completed = game.ReplicatedStorage.ModPanelRemoteFunction:InvokeServer(game.Players.LocalPlayer, playerText, newValue, "Name")
08        if not completed then
09            output(playerText.." is not a valid username.")
10        else
11            output("Sucessfully changed speed.")
12        end
13        local _, _ = pcall(function()
14            if game.Players:GetPlayerByUserId(playerText) then
15                local completed = game.ReplicatedStorage.ModPanelRemoteFunction:InvokeServer(game.Players.LocalPlayer, playerText, newValue, "Id")
View all 46 lines...

The output:

OnServerInvoke is a callback member of RemoteFunction; you can only set the callback value, get is not available

If you are able to help me I would greatly appreciate it.

0
I think you need to remove _ from type at line 4 hasanchik 49 — 4y
0
^ Okay, I'll try that. ParticularlyPenguin 71 — 4y
0
Nope, not the problem. ParticularlyPenguin 71 — 4y
0
Seems like you haven't invoked the remote function.. SilentsReplacement 468 — 4y
View all comments (4 more)
0
I have- ParticularlyPenguin 71 — 4y
0
You don’t need to pass player. InvokeServer and FireServer automatically pass the player SethHeinzman 284 — 4y
0
No, that's not the case. I just looked at the Roblox developer page and it said it didn't.' ParticularlyPenguin 71 — 4y
0
You still need player in the OnServerInvoke though SethHeinzman 284 — 4y

1 answer

Log in to vote
2
Answered by 4 years ago
Edited 4 years ago

OnServerInvoke is not an event connection. You have to assign a function to it like this:

1game.ReplicatedStorage.ModPanelRemoteFunction.OnServerInvoke = function(player, value, _type)
2 
3end

Additionally make sure on the client to NOT pass the player. Roblox automatically does this internally since the server always has to know who the remote event/function originated from:

1game.ReplicatedStorage.ModPanelRemoteFunction:InvokeServer(newValue, "Id")
0
Okay, thanks. ParticularlyPenguin 71 — 4y
Ad

Answer this question