#How to effectively update the leaderboard

46 messages · Page 1 of 1 (latest)

limpid nimbus
#

For further clarification, if i were to just type onPlayerJoin() it would not run

fickle fjord
#

also you are getting player in the function so it would probably error without sending one unless you are using oop

limpid nimbus
#

how would i check for leaderstats what method or code do i use? sorry for my illiteracy i just started learning lua & studio a few days ago

fickle fjord
#

you could use :FindFirstChild() inside the player

limpid nimbus
#

I see

#

But wouldnt that not work since player is inside of the function and can not be referred to outside of it

#

?

fickle fjord
#

like
player:FindFirstChild("leaderstats")

fickle fjord
#
function leaderstats(player: Player)
  local leaderstats = player:FFC("leaderstats")
  
end

Players.PlayerAdded:Connect(function(Player)
  leaderstats(Player)
end)
``` is this what you were asking?
limpid nimbus
#

I was asking how to reference the player outside of the function because if i were to type player:WaitForChild("leaderstats"):WaitForChild("Points").Value = x it would not work

#

let me see how the snippet you just sent works

fickle fjord
limpid nimbus
#

sorry?

fickle fjord
limpid nimbus
#

Ohh ok ill check that rn

fickle fjord
#

try to add for _,Player in game.Players:GetPlayers() do task.spawn(onPlayerJoin,Player) end

#

maybe the player joined before the script loaded

limpid nimbus
#

good news is it runs, bad news is that it still doesn't work. Whether this means we are closer or further from the gold is beyond me because i have the brain capacity of a walnut at the moment.

fickle fjord
#

lol

#

add print(player) after local function onPlayerJoin(player)

limpid nimbus
#

Prints player once so I'm inclined to think that it is running due to the line game.Players.PlayerAdded:Connect(onPlayerJoin) but not with the for loop

#

also the leaderBoardModule.updatePoints is being printed at the end of the method once so we can determine that it is running for sure, but not the other one

fickle fjord
#

wait

#

you never parented the leaderstats to the player

#

oh nvm

#

you did

#

try to change points to a NumberValue

limpid nimbus
#

This is horrendous i saw a 5 minute tutorial and thought this would be a quick in and out but now I feel deep regret for my actions

fickle fjord
#

lol

limpid nimbus
#

numberValue still keeps everything the same

#

this is the for loop btwfor _,Player in game.Players:GetPlayers() do onPlayerJoin(Player) end

fickle fjord
#

wait is there atleast a leaderstats?

limpid nimbus
#

I did also try the one that you did but it didnt work

limpid nimbus
fickle fjord
#

whats.. the problem

limpid nimbus
#

Im just running into issues trying to edit the points value

fickle fjord
#

what do you mean

limpid nimbus
#

Because I can't find a way to update the points value on the leaderboard past when it starts

#

lemme give a detailed explanation

#

This is a clicker game, so I want the leaderBoard to accurately display the players current points. However, I am unable to find how to alter the points variable within the method because leaderstats, player, and every other variable I need from it can not be accessed, or is not a detected global variable. I know the points of the module script are being updated because i debugged and saw it print the score as it rises, so i know for a fact it is within the leaderboard script that the problem resides. And my idea of what the problem is is the inability to update the points variable.

#

As you can see the Points on the leaderboard does not match with the points on the text

fickle fjord
#

how do you get hte points value in your game?

limpid nimbus
#

This is the leaderBoardModule method: ```leaderBoardModule = {}

leaderBoardModule.points = 0

function leaderBoardModule.updatePoints(points)
leaderBoardModule.points = points
end

function leaderBoardModule.getPoints()
return leaderBoardModule.points
end

return leaderBoardModuleI use this method to communicate the values from my pointManager script to my leaderBoard script. I know that the updatePoints method is being called because i put a print statement in it earlier, and for each event in the pointManager, script, it updated the points correctly. the getPoints method is also being called when the player loads into the game in the leaderBoard script, and works as planned. The problem is that I cant set the "points" variable in the leaderboard script equal to the points in the leaderBoard module, because I cant run theonPlayerJoin()``` past when the player enters the game.