Not sure why this is happening. OnServerEvent is stated in Documentation
-- ServerScript/ServerScriptService
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local event = ReplicatedStorage:FindFirstChild("RarityEvent")
if not event then
event = Instance.new("RemoteEvent")
event.Name = "RarityEvent"
event.Parent = ReplicatedStorage
end
local function createEvent(player, rarity)
print(player.Name .. " just discovered a " .. rarity)
end
ReplicatedStorage.RarityEvent.OnServerEvent:Connect(createEvent)
-- LocalScript/StarterplayerScripts
local RandomNumberGenerator = require(script.RandomNumberGenerator)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RanNumGui = game:GetService("StarterGui"):FindFirstChild("RandomNumberGui")
local button = RanNumGui.TextButton
button.MouseButton1Click:Connect(function()
local rarity = RandomNumberGenerator.Generate()
local textLabel = button.TextLabel
textLabel.Text = tostring(rarity)
if rarity ~= "Common" then
ReplicatedStorage:FindFirstChild("RarityEvent"):FireServer(game.Players.LocalPlayer, rarity)
end
end)
--ModuleScript/StarterPlayerScripts.LocalScript.RandomNumberGenerator
local module = {}
function module.Generate()
local rarity
local randomNumber = math.random(1, 10000)
if randomNumber <= 7500 then
rarity = "Common"
elseif randomNumber <= 9500 then
rarity = "Uncommon"
elseif randomNumber <= 9900 then
rarity = "Rare"
elseif randomNumber <= 9990 then
rarity = "Epic"
else
rarity = "Legendary"
end
return rarity
end
return module