So this is a script with a loop where the server should store a loop for each player diffrently, but it doesn’t. When the player clicks it sents a message to the server and the server pics a random number and sends it back to the player. But the loops collide with each other for some reason.
Can someone pelase help me with this.
local replicatedStorage = game:GetService("ReplicatedStorage")
local clickEvent = replicatedStorage:WaitForChild("RemoteEvents"):WaitForChild("ClickEvent")
local startEvent = replicatedStorage:WaitForChild("RemoteEvents"):WaitForChild("StartEvent")
local endEvent = replicatedStorage:WaitForChild("RemoteEvents"):WaitForChild("EndEvent")
local luckEvent = replicatedStorage:WaitForChild("RemoteEvents"):WaitForChild("LuckEvent")
local players = game:GetService("Players")
local debounce = false
local clickDebounce = false
players.PlayerAdded:Connect(function(player)
while true do
if debounce == false then
debounce = true
local luckTable = {}
local amount = 0
startEvent:FireClient(player)
clickEvent.OnServerEvent:Connect(function(player)
if clickDebounce == false then
clickDebounce = true
amount += 1
if amount < 10 then
local function getRandomValue(minValue, maxValue, uniformRandomValueModifier)
local uniformRandomNumber = math.random()
return minValue + uniformRandomValueModifier(uniformRandomNumber) * (maxValue - minValue)
end
local function exampleModifierFunction(uniformRandomNumber)
return uniformRandomNumber ^ 5 / player.Values.Chance.Value
end
-- example usage
local luckNumber = getRandomValue(1, player.Values.Range.Value, exampleModifierFunction)
luckNumber = math.floor(luckNumber + 0.5)
table.insert(luckTable, luckNumber)
luckEvent:FireClient(player,luckNumber,amount)
else
amount = 0
local totalLuck = 0
for i,v in pairs(luckTable) do
totalLuck += v
end
totalLuck /= 10
if totalLuck > player.leaderstats.Luck.Value then
player.leaderstats.Luck.Value = totalLuck
end
player.leaderstats.Rolls.Value += 1
player.Values.TotalLuck.Value += totalLuck
endEvent:FireClient(player,totalLuck)
debounce = false
for i,v in pairs(luckTable) do
table.clear(luckTable)
end
end
wait(0.5)
clickDebounce = false
end
end)
end
wait(1)
end
end)