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

Remote function giving a weird error?

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.

8 comments

0

I think you need to remove _ from type at line 4

0

^ Okay, I'll try that.

0

Nope, not the problem.

0

Seems like you haven't invoked the remote function..

0

I have-

0

You don’t need to pass player. InvokeServer and FireServer automatically pass the player

0

No, that's not the case. I just looked at the Roblox developer page and it said it didn't.'

0

You still need player in the OnServerInvoke though

1 answer

✓ Accepted answer

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")

1 comment

0

Okay, thanks.

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