Number sent through RemoteFunction as parameter turns into Instance

Hello, I’m trying to make a random number generator system, where lower numbers are more common. There’s nothing wrong with the number generation itself, however whenever I click a button to roll the numbers, It doesn’t work. It uses 2 parameters, luck, and base. (luck makes higher numbers more common depending on how high the number is, base determines how exponentially numbers get rarer by default.) I’m not sure how, but when I use the luck variable as a parameter for the RemoteFunction, it turns into an Instance, and the name of the Instance is the local player. Nothing seems to be wrong with the base variable, but I’m really not sure what to do from here.

Image of output after invoking the function

I haven’t tried really anything since I’m completely lost on how this could even be happening in the first place. Any help is very appreciated.

Client:

local player = game.Players.LocalPlayer
local auraboxtemplate = script.Box

script.Parent.Roll.MouseButton1Click:Connect(function()
	local luck = 1
	print("luck: "..luck)
	local base = 0.5
	print("base: "..base)
	game.ReplicatedStorage:WaitForChild("Remotes").RollFunction:InvokeServer(luck, base)
end)

Server:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")

local Remotes = ReplicatedStorage:WaitForChild("Remotes")
local RollFunction = Remotes:WaitForChild("RollFunction")

RollFunction.OnServerInvoke = function(luckLevel, baseRarity)
    print("luck:", luckLevel)
    print("base:", baseRarity)

    if typeof(luckLevel) ~= "number" or typeof(baseRarity) ~= "number" then
        warn("Invalid parameters: luckLevel and baseRarity must be numbers.")
        return nil
    end

    local randomValue = math.random()
    local baseNumber = 1 / randomValue
    local number = baseNumber * (luckLevel * baseRarity)
    number = math.floor(number * 100 + 0.5) / 100

    print("Generated number:", number)
    return number
end

If you have any questions or need more information, I’m happy to answer them.

1 Like

im gonna say something stupid, but try numbers with the S and the end, instead of number

1 Like

That didn’t seem to change anything, same result in output

1 Like

Okay, so I found the solution. Apparently RemoteFunctions automatically put the local player as a parameter, specifically the first one. You can’t see it in the local script, so it basically looks like it’s not there. The fix was just adding a third variable before luckLevel and baseLevel for the player.

RollFunction.OnServerInvoke = function(player, luckLevel, baseRarity)
    print("luck:", luckLevel)
    print("base:", baseRarity)

    if typeof(luckLevel) ~= "number" or typeof(baseRarity) ~= "number" then
        warn("Invalid parameters: luckLevel and baseRarity must be numbers.")
        return nil
    end

    local randomValue = math.random()
    local baseNumber = 1 / randomValue
    local number = baseNumber * (luckLevel * baseRarity)
    number = math.floor(number * 100 + 0.5) / 100

    print("Generated number:", number)
    return number
end
1 Like

ohh alright, i was checking the same thing. good job

2 Likes

For future reference, this is the same behavior for RemoteEvent.OnServerEvent

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.