Hi ya! I’m sorry if there is a simple fix to this, but I’ve just been trying to figure out why it’s broken for hours on end. I’m not sure if this is a studio bug or just an error on my part.
-
I’m making a voting system, with game mode and map voting. (I won’t include all code, just code related to the error)
-
When the game is setting attributes inside ReplicatedStorage. That contains the mapName/GamemodeName and Vote Number. Whenever I with the :SetAttribute() it creates a brand new Attribute, but it doesn’t load the value that it’s passed in with.
-
I’ve been looking through the devForum, videos reading over the Attributes APIs. I can’t manage to find a reason for why this is happening.
Module Script
local votingModule = {}
-- Services
local replicatedStorage = game:GetService("ReplicatedStorage")
local serverStorage = game:GetService("ServerStorage")
local mapsFolder = serverStorage.Maps -- Where the maps are stored
local gamemodesFolder = serverStorage.Gamemodes -- Where the gamemode parameters are stored.
local roundObjects = replicatedStorage.RoundObjects
local votingFolder = roundObjects.Voting
local map1 = votingFolder:WaitForChild("Map1")
local map2 = votingFolder:WaitForChild("Map2")
local map3 = votingFolder:WaitForChild("Map3")
local gamemode1 = votingFolder:WaitForChild("Gamemode1")
local gamemode2 = votingFolder:WaitForChild("Gamemode2")
local gamemode3 = votingFolder:WaitForChild("Gamemode3")
function votingModule.RandomiseMaps_Gamemodes()
-- gets the data tables
local gamemodeList = gamemodesFolder:GetChildren() -- returns a table of all current gamemodes in the game
local mapList = mapsFolder:GetChildren() -- returns a table of all the current maps in the game
-- chooses the 3 maps & gamemodes
local chosenMap1 = mapList[math.random(1, #mapList)]
local chosenMap2 = mapList[math.random(1, #mapList)]
local chosenMap3 = mapList[math.random(1, #mapList)]
local chosenGamemode1 = gamemodeList[math.random(1, #gamemodeList)]
local chosenGamemode2 = gamemodeList[math.random(1, #gamemodeList)]
local chosenGamemode3 = gamemodeList[math.random(1, #gamemodeList)]
-- makes sure the chosen maps are all different
repeat
chosenMap2 = mapList[math.random(1, #mapList)]
until chosenMap2 ~= chosenMap1 -- Repeats until chosenMap2 is NOT equal to
repeat
chosenMap3 = mapList[math.random(1, #mapList)]
until chosenMap3 ~= chosenMap1 and chosenMap3 ~= chosenMap2 -- Repeats until chosenMap2 is NOT equal to
-- makes sure all the chosen gamemodes are all different
repeat
chosenGamemode2 = gamemodeList[math.random(1, #gamemodeList)]
until chosenGamemode2 ~= chosenGamemode1 -- Repeats until chosenGamemode2 is NOT equal to
repeat
chosenGamemode3 = gamemodeList[math.random(1, #gamemodeList)]
until chosenGamemode3 ~= chosenGamemode1 and chosenGamemode3 ~= chosenGamemode2 -- Repeats until chosenMap2 is NOT equal to
print("--------- SELETED MAPS ---------")
print(chosenMap1.Name)
print(chosenMap2.Name)
print(chosenMap3.Name)
print("--------- SELETED GAMEMODES ---------")
print(chosenGamemode1.Name)
print(chosenGamemode2.Name)
print(chosenGamemode3.Name)
-- Sets all the mapName Attributes to the correct names
map1:SetAttribute("MapName", chosenMap1.Name)
map2:SetAttribute("MapName", chosenMap2.Name)
map3:SetAttribute("MapName", chosenMap3.Name)
print("Set MapNames")
-- Sets all the gamemodeName Attributes to the correct names
gamemode1:SetAttribute("GamemodeName", chosenGamemode1.Value)
gamemode2:SetAttribute("GamemodeName", chosenGamemode2.Value)
gamemode3:SetAttribute("GamemodeName", chosenGamemode3.Value)
print("Set GamemodeNames")
-- Sets all the VoteCoumt Attributes to 0 (Just to be safe)
map1:SetAttribute("VoteCount", 0)
map2:SetAttribute("VoteCount", 0)
map3:SetAttribute("VoteCount", 0)
-- Sets all the VoteCoumt Attributes to 0 (Just to be safe)
gamemode1:SetAttribute("VoteCount", 0)
gamemode2:SetAttribute("VoteCount", 0)
gamemode3:SetAttribute("VoteCount", 0)
return true
end
ServerScript
-- Services
local ServerScriptService = game:GetService("ServerScriptService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- Module Scripts
local votingModule = require(ServerScriptService.Game_VotingManager.VotingModule)
-- Folders
local roundObjects = ReplicatedStorage:WaitForChild("RoundObjects")
game.Players.PlayerAdded:Connect(function(player)
local debounce_Vote = false
if roundObjects:GetAttribute("InRound") == true then -- A round is currently Active
elseif roundObjects:GetAttribute("InRound") == false then -- No Round is currently Active
local votingCheck = votingModule.RandomiseMaps_Gamemodes()
end
end)
In the module script, all the print statements are fired. But the :SetAttribute() never fills in it’s value. After it’s like chosenMap1/chosenGamemode1 I’ve tried .Value, .Name, nothing but it still doesn’t work. I’m sorry if this is the wrong section, or I’ve made a really simple error. I also have this same problem in my other project