What do you want to achieve?
I want to pick the local player’s multiplier value in Lua for my Roblox game. What is the issue?
I have a script that gives clicks to the player based on their multiplier value. However, I don’t know how to pick the local player’s leaderstats value. I need help with this issue. What solutions have you tried so far?
I have looked for solutions on the Developer Hub, but I couldn’t find any that specifically addressed my issue. I have tried using the PlayerAdded event to get the local player’s multiplier value, but I was not successful.
Here is the script that I am currently using:
local rebirthEvent = game.ReplicatedStorage:WaitForChild("RebirthEvent")
local function giveClicks(plr)
local clicksStat = plr.leaderstats.Clicks
local multiplier = plr.leaderstats.Multiplier.Value
if multiplier > 0 then
clicksStat.Value += 1 * multiplier
else
clicksStat.Value += 1
end
end
game.ReplicatedStorage.GiveClicks.OnServerEvent:Connect(function(plr)
giveClicks(plr)
end)
game.ReplicatedStorage.GiveAutoClicks.OnServerEvent:Connect(function(plr)
giveClicks(plr)
end)
This script seems correct. Could you detail what you expect to happen vs what is really happening with your script.
The server doesn’t have a local player, that’s why there is the plr parameter in your functions, it will be which ever client fired the Give[Auto]Clicks event.
My issue is that the script doesn’t seem to be giving the correct number of clicks based on the player’s multiplier value. The clicksStat.Value seems to be adding 1 instead of 1 multiplied by the player’s multiplier value.
Make sure the MultiplierValue starts as 1 for any new players, so make sure to edit this value for any players who have already played the game, so change their value to also 1.
When they rebirth you want to set their Clicks to 0 (probably) and then add a value to their Multiplier value.
Then each time they click you want to basically do what you did in your example script, except for the rebirth.
So basically:
local function rebirth(player)
local multiplier = plr.leaderstats.Multiplier
local current = math.max(1, multiplier.Value) -- gets the highest value
multiplier.Value = multiplier.Value + 1 -- change this any way you see fit
end
rebirthEvent.OnServerEvent:Connect(rebirth)
local function giveClicks(plr)
local clicks = plr:WaitForChild("leaderstats").Clicks
local multiplier = plr:WaitForChild("stats").Multiplier
if multiplier > 0 then
clicks.Value += 1 * multiplier
else
clicks.Value += 1
end
end
game.ReplicatedStorage.GiveClicks.OnServerEvent:Connect(function(plr)
giveClicks(plr)
end)
game.ReplicatedStorage.GiveAutoClicks.OnServerEvent:Connect(function(plr)
giveClicks(plr)
end)
You’ve changed your script to use :WaitForChild but forgot to get the .Value of your multiplier, either at declaration like it was in the original script, or at the call sites like clicks will work.