local GameFunc = {}
local players = game:GetService("Players")
local UI = script:WaitForChild("ChoiceTemplate")
local GoodChoices = {
--// Health //--
["IncreaseHP"] = { -- This will be the ID of the event.
Display = "Gain %d max HP.", --> Format with amount of HP gained. (Randomized), appears in the GUI
Rarity = 1 -- How rare the event is, the lower the rarer.
},
--// DAMAGE //--
["IncreaseDMG"] = {
Display = "Deal %d more damage.",
Rarity = 1
},
--// JUMPHEIGHT //--
["IncreaseJP"] = {
Display = "Jump %d studs higher.",
Rarity = 1
},
--// WALKSPEED //--
["IncreaseWS"] = {
Display = "Walk %d studs/s faster.",
Rarity = 1
},
}
local BadChoices = {
["DecreaseHP"] = {
Display = "Lose %d max HP", --> Format with amount of HP lost. (Randomized)
Rarity = 1
},
["DecreaseDMG"] = {
Display = "Gain %d more damage.",
Rarity = 1
},
["DecreaseJP"] = {
Display = "Jump %d studs lower.",
Rarity = 1,
},
["DecreaseWS"] = {
Display = "Walk %d studs/s slower.",
Rarity = 1
},
}
GameFunc.GoodChoices = GoodChoices
GameFunc.BadChoices = BadChoices
--//// RARITY / WEIGHT CALCULATIONS \\\\--
function GameFunc:SelectChoice(choices)
local TotalWeight = 0
for _, choice in pairs(choices) do
TotalWeight = TotalWeight + (1 / choice.Rarity)
end
local RandomWeight = math.random() * TotalWeight
local CumulativeWeight = 0
for INDEX, choice in pairs(choices) do
CumulativeWeight = CumulativeWeight + (1 / choice.Rarity)
if RandomWeight <= CumulativeWeight then
return INDEX, choices[INDEX]
end
end
end
function GameFunc:SendChoice()
local currentParticipants = players:GetPlayers()
for _, player in pairs(currentParticipants) do
if player:IsA("Player") and player.Team == game:GetService("Teams").Participating then
if player.Character:FindFirstChild("Humanoid").Health > 0 then
local UiClone = UI:Clone()
local choice1 = UiClone:WaitForChild("ChoiceFrame1")
local choice2 = UiClone:WaitForChild("ChoiceFrame2")
local indexGoodResult1, choiceGood1 = GameFunc:SelectChoice(GoodChoices)
local indexGoodResult2, choiceGood2 = GameFunc:SelectChoice(GoodChoices)
local indexBadResult1, choiceBad1 = GameFunc:SelectChoice(BadChoices)
local indexBadResult2, choiceBad2 = GameFunc:SelectChoice(BadChoices)
choice1.Effect1.Text = GameFunc:SelectChoice(GoodChoices)
end
end
end
end
return GameFunc
I’m making a sort of would you rather game to say the least. Here’s the thing, I don’t know how to handle it properly. I don’t want to handle things on the client for obvious reasons, but I don’t know how I’d handle things on the server.
For instance, the INDEX is what is considered the ID of the result, so I’d need to move it to the server and check the INDEX to see what type of event it is. Then, simply do the thing.
I’d like a little insight on how to do what I want.
This is the hierarchy of the GUI: