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.