Hello, i’m pretty new to this forum all i was doing in the past was reading the posts of others but now i encountered a problem that i’ve been trying to fix since a long time.
Basically, i’m making a Truth or Dare game where the player have to choose between truth or dare and there is an announcement textlabel that display what is the server currently doing and there is a part where it says “Choosing a random Question from " … amount_of_questions (in the datastore) … " Questions.”
THE PROBLEM :
it says there is 13 questions even tho i added only like 3-4 questions.
MY CODE :
if response == "Truth" then
local pages = Questions:ListKeysAsync(nil, 100)
local counter = 0
while true do
for _, key in pairs(pages:GetCurrentPage()) do
counter += 1
warn(key.KeyName)
end
if pages.IsFinished then
break -- Exit loop if we've looped over all pages
end
-- Get new page (same API limit as calling 'ListKeysAsync')
pages:AdvanceToNextPageAsync()
end
Announce:FireAllClients("Picking a Random Question from "..counter.." Questions.")
wait(3)
local randomIndex = math.random(1, counter)
local success5, errormsg5 = nil, nil
local attempt5 = 1 -- how many attemps
repeat -- attempt to get data
success5, entity = pcall(function()
return Questions:GetAsync(randomIndex)
end)
attempt5 += 1
if not success5 then
warn(entity)
task.wait(3)
end
until success5 or attempt5 == 5
warn(entity)
if checkifplayer(choosen_player) == true then
questionning = true
Announce:FireAllClients(choosen_player.Name .. "... " .. tostring(entity))
ServerMessage:FireAllClients(choosen_player.Name .. "... " .. tostring(entity))
for i=-70, 0 do
Announce:FireAllClients(choosen_player.Name .. "... " .. tostring(entity) .. "(".. math.abs(i) .. ")")
if checkifplayer(choosen_player) == false or responded then questionning = false break end
wait(1)
end
if checkifplayer(choosen_player) and responded ~= false then
wait(1)
Announce:FireAllClients(choosen_player.Name.." Responded : ".. responded)
ServerMessage:FireAllClients(choosen_player.Name.." Responded : ".. responded)
-- feature to make players vote if they should give him gems
wait(8)
end
else
intialize()
break
end