I am trying to make a simple random chance winner with math.random so that when the player clicks R a random number is selected and if that number is more than or equal to 56, text is printed on the server that says the player “won”, but if they lose, text is printed on the client saying they “lost”.
However. when I run the code, an error comes up saying this.
NOTE: I am purposefully using remote functions because I want to get familiar with them as a beginner scripter.
This is the code from the server script:
local rs = game:GetService("ReplicatedStorage")
local roll = rs:FindFirstChild("Rollin")
local loser = rs:FindFirstChild("rolled")
local function decidewinner(player, number)
if number >= 56 then
print(player.Name.." has won!")
else
loser:InvokeClient(player)
end
end
roll.OnServerInvoke = decidewinner
This is the code from the client script:
local rs = game:GetService("ReplicatedStorage")
local UIS = game:GetService("UserInputService")
local roll = rs:FindFirstChild("Rollin")
local rolling = rs:FindFirstChild("rolled")
local player = game.Players.LocalPlayer
if player then
local function breakinnews(plr)
plr = player
print(player.Name.." has lost... Better Luck Next Time")
end
rolling.OnClientInvoke = breakinnews
UIS.InputBegan:Connect(function(input, isTypin)
if isTypin then return end
if input.KeyCode == Enum.KeyCode.R then
local randomnumber = math.random(1,100)
print(player.Name.." is Rolling...")
task.wait(2)
roll:InvokeServer(player, randomnumber)
end
end)
end
The code works fine(well doesn’t come up with any error) if I only do == and not >= or <= in the if statement in the decidewinner function.