Hi!
I have a function that takes two arguments, a StringValue object and a variable that is set to update with my desired result. My issue is with the updating of the second argument.
I've used print() to determine that I'm indexing the correct value and yet I still can't get the result I've want, so I've deduced that either this is impossible or I'm making a major mistake.
Here is my code:
local uis = game:GetService("UserInputService")
local players = game:GetService("Players")
local player = players.LocalPlayer
local stances = {
["Water"] = {
[1] = {5, ""},
[2] = {10, ""},
[3] = {15, ""},
[4] = {20, ""},
[5] = {35, ""}
} ,
["Earth"] = {
[1] = {5, ""},
[2] = {10, ""},
[3] = {15, ""},
[4] = {20, ""},
[5] = {35, ""}
} ,
["Fire"] = {
[1] = {5, ""},
[2] = {10, ""},
[3] = {15, ""},
[4] = {20, ""},
[5] = {35, ""}
} ,
["Air"] = {
[1] = {5, ""},
[2] = {10, ""},
[3] = {15, ""},
[4] = {20, ""},
[5] = {35, ""}
} ,
}
local key = "T"
function setStance(Element, Stance)
if stances[Element] then
local rng = math.random(1, 5)
if stances[Element][rng][1] then
Stance = stances[Element][rng][1]
return true
else
return false
end
else
return false
end
end
uis.InputBegan:connect(function(input, gameProcessedEvent)
if input.KeyCode.Name == key and not gameProcessedEvent then
local plrElement = player:FindFirstChild("Element").Value --I've set this value to Fire, this isn't the issue. I've already used print() to figure out that it isn't an issue with my values
local stance
if setStance(plrElement, stance) then
print(stance)
else
print("Error")
end
end
end)
To clarify more, declaring a variable with no value will set the variable's value to nil, and upon printing stance after confirming that it has updated in the function, I get nil.
This is really stumping me. If I could get a reason why this is happening it'd be very appreciated. Thanks!

2 comments
Thank you for clarifying!
No problem!