#Leaderstat not working
1 messages · Page 1 of 1 (latest)
game.Players.PlayerAdded:Connect(function()
local leaderstats = Instance.new('Folder', player)
leaderstats.Name = 'Leaderstats'
local clicks = Instance.new('IntValue', leaderstats)
clicks.Name = 'Clicks'
clicks.Value = 0
end)
its nothing big but its the firstg thing im attempting on my own
Lol yeah I figured.
thats my ClicksDisplay
so, Try setting the folders name into leaderstats in lowecase
okay
lowercase
didnt work
do you need my ClickButton code?
Sure.
its a local script also
script.Parent.MouseButton1Click:Connect(function()
local plr = game.Players.LocalPlayer
local clicks = plr:WaitForChild('leaderstats'):WaitForChild('Clicks')
clicks.Value = clicks.Value + 1
script.Parent.Parent.TextLabel.Text = clicks.Value
end)
Where is the local script located
So startergui.
yes
There are 2 problems here
Yeah thats probably because
The first script is not running
is it a local script
the local?
** You are now Level 2! **
No, the server
ah, that figures
huh
oops
on the local button script
yes
you should use tostring() on the number value
because AFAIK you cant set a text to an number
okay
K, now playtest and tell me the results
will do
does this look right
script.Parent.MouseButton1Click:Connect(function()
local plr = game.Players.LocalPlayer
local clicks = plr:WaitForChild('leaderstats'):WaitForChild('Clicks')
clicks.Value = clicks.Value + 1
script.Parent.Parent.TextLabel.Text = tostring(clicks.Value)
end)
yup
no problem
Theoretically it works
It works only for you, however other people wont see any change in the leaderboard since that script changes the clicks value on the clients side instead of the server. That means, you may see whatever amount you clicked, others see 0.
oh
so what do you suggest?
To fix that, add a remote function in prefferably ReplicatedStorage and let a server script listen to that remote
and then change it via the server script
May I fix the scripts for you? May take a while because im on mobile
and if you have any questions about the script just ask
Alr then give me a few
hows it coming along
nah its all good no rush
Step 1: Replace your leaderstats script with this:
game.Players.PlayerAdded:Connect(function(plr)
if not plr:FindFirstChild(“leaderstats”) then
local leaderstats = Instance.new(“Folder”)
leaderstats.Name = “leaderstats”
leaderstats.Parent = plr
end
if not leaderstats:FindFirstChild(“Clicks”) then
local clicks = Instance.new(“NumberValue”)
clicks.Parent = leaderstats
clicks.Name = “Clicks”
end
end)
Step 2: Place a REMOTE EVENT in REPLICATED STORAGE and call it “updateClicks”
Step 3: Replace your local script with this:
local clickAmount = INSERT AMOUNT
script.Parent.MouseButton1Click:Connect(function()
local player = game.Players.LocalPlayer
game.ReplicatedStorage:FindFirstChild(“updateClicks”):FireServer(clickAmount)
end)
Step 4: Add a new SERVER script in ServerScriptService and insert this script:
game:GetService(“ReplicatedStorage”):FindFirstChild(“updateClicks”).OnServerEvent:Connect(function(player, clickAmount)
player:FindFirstChild(“leaderstats”):FindFirstChild(“Clicks”).Value = player:FindFirstChild(“leaderstats”):FindFirstChild(“Clicks”).Value + clickAmount
end)
lmk if there are any errors
or if it works
loading back in studio now ill lyk
read lines ok? @versed ruin
i got it it works 🙂
oh wait
** You are now Level 3! **
somewhat
alr let me fix it, i see why it isnt working
wym?
ooooh lol
sorry if i didnt like make that known lo
the game idea i have is every click rewinds or speeds up a frozen moment in time ur stuck in a time loop and your clicking unfreezes objects reveals secrets and eventually breaks reality over and over
sum like that
havnt decided lol itll bea long time
If ur a beginner, I should warn you about starting big projects immediately
im not its just a future idea
right now i wann just make a super simple thing and see how it goes
heres the entire instruction again, im kinda too lazy to send singular
Step 1: Replace your leaderstats script with this:
game.Players.PlayerAdded:Connect(function(plr)
if not plr:FindFirstChild(“leaderstats”) then
local leaderstats = Instance.new(“Folder”)
leaderstats.Name = “leaderstats”
leaderstats.Parent = plr
if not leaderstats:FindFirstChild(“Clicks”) then
local clicks = Instance.new(“NumberValue”)
clicks.Parent = leaderstats
clicks.Name = “Clicks”
end
end
end)
⸻
Step 2: Place a RemoteEvent in ReplicatedStorage and call it “updateClicks”
⸻
Step 3: Replace your local script with this:
local clickAmount = INSERT AMOUNT
local currentAmount = 0
script.Parent.MouseButton1Click:Connect(function()
currentAmount = currentAmount + 1
script.Parent.Text = tostring(currentAmount)
local player = game.Players.LocalPlayer
game.ReplicatedStorage:FindFirstChild(“updateClicks”):FireServer(clickAmount)
end)
⸻
Step 4: Add a new server script in ServerScriptService and insert this script:
game:GetService(“ReplicatedStorage”):FindFirstChild(“updateClicks”).OnServerEvent:Connect(function(player, clickAmount)
player:FindFirstChild(“leaderstats”):FindFirstChild(“Clicks”).Value = player:FindFirstChild(“leaderstats”):FindFirstChild(“Clicks”).Value + clickAmount
end
trying no
now
okay now neither works lol
i dont evne have a leaderstats folder anymore when test playing
😐
that seems like i did a stupid mistake lol