This is basically the only other script that relies on the module script, is there anything you can see here that would be causing it to not function properly?
local Players = game:GetService("Players")
local Rewards = require(game.ReplicatedStorage.Rewards)
Players.PlayerAdded:Connect(function(player)
game.ReplicatedStorage.Function.OnInvoke = function()
local FakeRewards, Reward = {}, nil
for i = 1, 10 do
FakeRewards[i] = Rewards:MakeNewReward()
end
Reward = Rewards:MakeNewReward()
player.leaderstats.Cash.Value += Reward[3]
player.leaderstats.Rolls.Value += 1
return FakeRewards, Reward
end
end)
there is also this script which invokes the server but i dont think it would be that
local canClick = true
script.Parent.Roll.MouseButton1Click:Connect(function()
if not canClick then return end
canClick = false
local fakeRewards, reward = game.ReplicatedStorage.Function:Invoke()
script.Parent.RollFrame.RewardContainer.RewardText.Text = reward[1]
script.Parent.RollFrame.RewardContainer.RewardChance.Text = '1 in '..tostring(reward[2])
script.Parent.RollFrame.RewardContainer.RewardPrice.Text = '$'..reward[3]
game.Workspace.GameTime.Value = 3
script.Parent.Parent.Countdown.TextLabel.Visible = true
script.Parent.RollFrame.Visible = true
wait(3)
script.Parent.RollFrame.Visible = false
script.Parent.Parent.Countdown.TextLabel.Visible = false
canClick = true
end)
I believe it’s beacuse of refering to LocalPlayer in the Rewards script cuz you’re trying to call the function on a server side while ModuleScript is thinking that he’s being run on a client. Try removing player variable, and adding player when calling function
local Players = game:GetService("Players")
local Rewards = require(game.ReplicatedStorage.Rewards)
Players.PlayerAdded:Connect(function(player)
game.ReplicatedStorage.Function.OnInvoke = function()
local FakeRewards, Reward = {}, nil
for i = 1, 10 do
FakeRewards[i] = Rewards:MakeNewReward(player)
end
Reward = Rewards:MakeNewReward(player)
player.leaderstats.Cash.Value += Reward[3]
player.leaderstats.Rolls.Value += 1
return FakeRewards, Reward
end
end)
local module = {
rewards = {
{
Name = 'Common',
Chance = 50,
Price = 10
},
{
Name = 'Uncommon',
Chance = 10,
Price = 25
},
{
Name = 'Rare',
Chance = 5,
Price = 100
},
{
Name = 'Epic',
Chance = 2,
Price = 750
}
}
}
--
local MaxNum = 0
for i,v in pairs(module.rewards) do
MaxNum += v.Chance
end
-- !! The higher the chance, the more often the rarity is picked
-- !! Chance should be an integer
-- !! Luck should not be negative or equal to 0
function module:MakeNewReward(player : Player)
luck = player.Luck.Luck.Value
local _ReturnTab
local chancePicked = math.random(1, MaxNum / luck)
-- You can either put division in or out the brackets
local totalChance = 0
warn('Random Number Choosen: '..chancePicked)
for i,v in pairs(module.rewards) do
totalChance += v.Chance
if totalChance >= chancePicked then
warn('Reward choosen, RewardChance '..v.Chance..' & RandomNum '.. chancePicked .. 'PRICE:'.. v.Price)
_ReturnTab = table.clone(v)
break
end
end
return _ReturnTab
end
return module
Okay so re adding the wait before the function was called stopped the errors showing but clicking the button still has no function, just no errors showing now
Right okay it still doesnt want to work EDIT: I just changed where the Wait was and i have some kind of a result here not fully functioning but its printing stuff atleast
local module = {
rewards = {
{
Name = 'Common',
Chance = 50,
Price = 10
},
{
Name = 'Uncommon',
Chance = 10,
Price = 25
},
{
Name = 'Rare',
Chance = 5,
Price = 100
},
{
Name = 'Epic',
Chance = 2,
Price = 750
}
}
}
--
local MaxNum = 0
for i,v in pairs(module.rewards) do
MaxNum += v.Chance
end
-- !! The higher the chance, the more often the rarity is picked
-- !! Chance should be an integer
-- !! Luck should not be negative or equal to 0
function module:MakeNewReward(player : Player)
luck = player.Luck.Luck.Value
local _ReturnTab
local chancePicked = math.random(1, MaxNum / luck)
-- You can either put division in or out the brackets
local totalChance = 0
warn('Random Number Choosen: '..chancePicked)
for i,v in pairs(module.rewards) do
totalChance += v.Chance
if totalChance >= chancePicked then
warn('Reward choosen, RewardChance '..v.Chance..' & RandomNum '.. chancePicked .. 'PRICE:'.. v.Price)
_ReturnTab = {
v.Name,
v.Chance,
v.Price
}
break
end
end
return _ReturnTab
end
return module
local canClick = true
script.Parent.Roll.MouseButton1Click:Connect(function()
if not canClick then return end
canClick = false
local fakeRewards, reward = game.ReplicatedStorage.Function:Invoke()
script.Parent.RollFrame.RewardContainer.RewardText.Text = reward[1]
script.Parent.RollFrame.RewardContainer.RewardChance.Text = '1 in '..tostring(reward[2])
script.Parent.RollFrame.RewardContainer.RewardPrice.Text = '$'..reward[3]
game.Workspace.GameTime.Value = 3
script.Parent.Parent.Countdown.TextLabel.Visible = true
script.Parent.RollFrame.Visible = true
wait(3)
script.Parent.RollFrame.Visible = false
script.Parent.Parent.Countdown.TextLabel.Visible = false
canClick = true
end)
I’ve pretty changed it back how it was so try this