and the ModuleScript for the spinning system looks like this:
local weight = 0
for _, chance in pairs(rewardModule.spinChance) do
weight += (chance * 10)
end
local runNumber = math.random(1, weight)
task.wait()
weight = 0
for prize, chance in pairs(rewardModule.spinChance) do
weight += (chance * 10)
if weight >= runNumber then
print(plr.Name.." got "..prize)
return prize
end
end
I ran the function from the ModuleScript through a ServerScript and sent the information on where it should land to the client.
The part of the code where it sends the info looks like this.
local prize = rewardModule.Spin(plr)
--Full spins is 4 and DegreeToSpin is 360/5 = 72
local endRotation = -((360 * -fullspins) + (degreetospin) * (#prize - 1))
rp:FindFirstChild("Spin"):FireClient(plr, endRotation)
Well, here’s what you need to realize: every segment spans 360/5 degrees. That’s 72 degrees. Depending on what the result is, you should change the amount it rotates. first, calculate the offset. This is the index times the 72 degrees. Nothing = 0, ticket UGC = 1, 1 spin = 2, etc.
Then, from that offset, you must always rotate 360 degrees. So if the result is Ticket UGC (1x72), then you may only rotate to 72, 432, 792, etc. If the result is the 3rd option, then you do 3x72, and start counting from there.
This’ll rotate it to exactly in the center every time, but you have 72/2 degrees in either direction, so you should add or substract a random value to the end rotation, so it doesn’t stop in the middle.
Well if you’re printing #prize, then you’re probably printing the length of the string or something.
Because you have a dictionary instead of an array, you can’t count the indices (as they are not ordered). You should make a second array, which is spinOrder, and it’s the order of the keys.
spinOrder = {
"1Nothing", "2Extra1Spin", "3Extra3Spin" ...}
local index = table.find(spinOrder, prize)
There’s 2 kinds of tables. Arrays, and dictionaries. Arrays count up an index, 1,2,3… whereas Dictionaries have keys that map to a value.
You can iterate over arrays, but not over dictionaries (also known as hashmaps), because the keys aren’t in any specific order. That’s also the difference between in pairs and in ipairs, btw, in ipairs can only be used for an array, and is faster than in pairs.
Also, a lot of table methods won’t work on dictionaries. Like table.insert(), because that tries to append a value to the end of the table, but because a dictionary isn’t ordered, that’s impossible.