If this was getting the random chosen armor
local newArmor = ArmorModule.chooseRandom():Clone()
How would i get the Armor that was chosen and put it in this variable
local Armor =
If this was getting the random chosen armor
local newArmor = ArmorModule.chooseRandom():Clone()
How would i get the Armor that was chosen and put it in this variable
local Armor =
The armor is already in newArmor so just place it into Armor. Or are these in two separate scripts?? Sorry a bit confusing what you’re asking for if you could be a bit more specific. What does chooseRandom() return?
So chooseRandom() calls a module script to do this:
armormodule.chooseRandom = function()
local randomNumber = math.random()*sum
local counter = 0
for rarity, weight in pairs(armormodule.rarities) do
counter = counter + weight
if randomNumber <= counter then
local rarityTable = armormodule.armors[rarity]
local chosenArmor = rarityTable[math.random(1,#rarityTable)]
return chosenArmor
And then gets the chosen armor and uses it as “newArmor”
Okay so newArmor now has a new cloned instance of the random armor, so you could write:
local Armor = newArmor
but I feel that would be redundant if you could just use the newArmor variable at that point. Unless Armor defines a player’s data variable. But that’s how you’d move newArmor into Armor within the same script and scope.
The problem is “newArmor” is in a event and im doing this in a function above the event so the “newArmor” Comes out to be a unknown global
So just to be clear where is newArmor in terms of server/local script and where is Armor?
Ah okay so they’re not the same scope. So Armor would have to be initiatied to a valid value first of all. newArmor doesn’t exist in Armor’s scope yet. However, whenever you use newArmor such as in your client event you can set Armor = newArmor below the line.
local Armor = nil -- or the default armor for your game
local newArmor = ...
Armor = newArmor
Make sure to set it to Armor because variables are case-sensitive, but yes that’s the position you want to place it in.
“Armor” is not the same thing as “armor” in variable definition.
Weird, what does the error say? Hover your mouse over the error.
And you do have
local Armor = nil
defined at the beginning?
yes
Please post your code in the proper format, not screenshots.
Whenever you clone the armor, instead of setting a new variable for it, just set Armor
a pointer to it.
if not IsEmpty then
Armor = Armor:Clone()
Armor:SetPrimaryPartCFrame(CFrame.fromOrientation(0, 45, 0))
Armor.Parent = newTemplate.VP
end
should i still keep this?
local Armor = newArmor
There is no need, no you don’t have to.
so what do i set it to?
nil?