Hello, for some reason the game is saying that my function is a nil value even though its defined. I'm using data store for the values my function changes. It was working fine but when I added another way to get said value it threw that error.
I'm sorry if I'm poorly explaining this. Okay, breakdown... Basically, the game has matches, when said matches are won they give the player who won the a value called "Skill Points", which is stored in data store. For some reason, when attempting to call the function that adds skill points, it gives me an error like this:
01:22:35.927 - ServerScriptService.MainScript:474: attempt to call global 'awardskillpoints' (a nil value)
01:22:35.929 - Stack Begin
01:22:35.929 - Script 'ServerScriptService.MainScript', Line 474
01:22:35.930 - Stack End
awardskillpoints is the name of my function, here is the script...
function awardskillpoints(player, skillpoints)
if player ~= nil and skillpoints ~= nil and skillpointdebounce == false then
skillpointdebounce = true
local mydata = playerdata[player.userId]
if mydata ~= nil then
mydata.skillpoints = mydata.skillpoints + skillpoints
local skillpointsvalue = player:FindFirstChild("Skill Points")
if skillpointsvalue ~= nil then
skillpointsvalue.Value = mydata.skillpoints
delay(1.2, function ()
skillpointdebounce = false
end)
end
end
end
end
end
when I call the function, I call it like this: "awardskillpoints(player, #ofpoints).
I always make sure player is defined wherever I call the function. Here is my win conditions.
for _, player in pairs(players) do
if player ~= nil then
if matchresults == "KillerWins" and player == killer then
awardskillpoints(player, 3)
awardwin(player)
awardxp(player, 100)
elseif matchresults == "CiviliansWin" and player ~= killer and player ~= officer and player ~= subofficer then
awardskillpoints(player, 4)
awardwin(player)
awardxp(player, 100)
elseif matchresults == "OfficerWins" and player == officer then
awardskillpoints(player, 4)
awardwin(player)
awardxp(player, 100)
elseif matchresults == "SuvOfficerWins" and player == subofficer then
awardskillpoints(player, 5)
awardwin(player)
awardxp(player, 100)
elseif player == killer or player == officer or player == civilian or player == subofficer then
awardxp(player, 50)
else
awardskillpoints(player, 0)
end
end
end
end
the function works fine when ever its called within these parameters.
Here is where I'm trying to call the function.
-- Round end conditions.
-- Timer ends.
local localtimer = roundtimer
while localtimer > 0 do
wait(1)
localtimer = localtimer - 1
timertag.Value = localtimer
aliveplayers = {}
killeralive = false
officeralive = false
subofficeralive = false
civilianalive = false
for _, player in pairs(players) do
if player ~= nil then
awardskillpoints(player, 1)
local character = player.Character
if character ~= nil then
local alivetag = character:FindFirstChild("AliveTag")
local humanoid = character:FindFirstChild("Humanoid")
if alivetag ~= nil and humanoid ~= nil and humanoid.Health > 0 then
awardskillpoints(player, 1)
awardxp(player, 25)
if player == killer then
killeralive = true
elseif player == officer then
officeralive = true
elseif player == subofficer then
subofficeralive = true
elseif player == civilian then
civilianalive = true
end
table.insert(aliveplayers, player)
end
end
end
end
-- if one player is alive, or killer is dead.
if #aliveplayers <= 1 or killeralive == false then
break
end
end
I tried calling it twice here, one for players participation and one for if the players lived. each one gives me the error shown above.
I'm not sure why its doing this, and to my understanding this is all the script needed to be seen. player is defined where I want to add the function, and the number of skill points.
So how can I fix my script to allow me to call the function elsewhere besides where the game end conditions are?
I hope this question actually gets answered, a lot of mine don't lol.
Thanks in advance.
