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:



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.

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:

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")
0
Okay, thanks. ParticularlyPenguin 71 — 4y
Ad

Answer this question