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:
local DSS = game:GetService("DataStoreService") local SpeedStore = DSS:GetDataStore("SpeedStore") game.ReplicatedStorage.ModPanelRemoteFunction.OnServerInvoke:Connect(function(sender, player, value, _type) -- Where the error is if sender:GetRankInGroup(6323488) >= 2 then if _type then if _type == "Name" then game.Players:FindFirstChild(player):WaitForChild("leaderstats"):WaitForChild("Speed").Value = value return true elseif _type == "Id" then game.Players:GetPlayerByUserId(player):WaitForChild("leaderstats"):WaitForChild("Speed").Value = value return true end elseif not _type then local key = player local data local s, eM = pcall(function() data = SpeedStore:GetAsync(key) end) if s and data then local s2, eM2 = pcall(function() SpeedStore:SetAsync(key, value) end) return true elseif not data then return false end end else sender:Kick("gg") -- Anti-Exploit end end)
My local script:
local playerGui = game.Players.LocalPlayer:WaitForChild("PlayerGui") local playerText = playerGui.ModPanel.MainFrame.NameOrUserId.Text local newValue = playerGui.ModPanel.MainFrame.NewValue.Text script.Parent.MouseButton1Click:Connect(function() if game.Players:FindFirstChild(playerText) then local completed = game.ReplicatedStorage.ModPanelRemoteFunction:InvokeServer(game.Players.LocalPlayer, playerText, newValue, "Name") if not completed then output(playerText.." is not a valid username.") else output("Sucessfully changed speed.") end local _, _ = pcall(function() if game.Players:GetPlayerByUserId(playerText) then local completed = game.ReplicatedStorage.ModPanelRemoteFunction:InvokeServer(game.Players.LocalPlayer, playerText, newValue, "Id") if not completed then output(playerText.." is not a valid User Id.") else output("Sucessfully changed speed.") end else local completed = game.ReplicatedStorage.ModPanelRemoteFunction:InvokeServer(game.Players.LocalPlayer, playerText, newValue, nil) if not completed then output(playerText.." is not a valid User Id") else output("Sucessfully changed speed.") end end end) end end) function output(text) if playerGui.ModPanel.OutputFrame.Visible == false then playerGui.ModPanel.OutputFrame.Visible = true playerGui.ModPanel.OutputFrame.TextLabel.Text = text playerGui.ModPanel.OutputFrame:TweenPosition( UDim2.new(0.338, 0,0.083, 0), "Out", "Elastic", 1) else playerGui.ModPanel.OutputFrame.TextLabel.Text = text end end
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.
OnServerInvoke is not an event connection. You have to assign a function to it like this:
game.ReplicatedStorage.ModPanelRemoteFunction.OnServerInvoke = function(player, value, _type) end
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:
game.ReplicatedStorage.ModPanelRemoteFunction:InvokeServer(newValue, "Id")