Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Why leaderstats don't apear?

Asked by 3 years ago

I try make a clicker game and I finded a tutorial on youtube but I cannot make leaderstats work.Here's the script I finded: local event = Instance.new("RemoteEvent") event.Name = "AddStats" event.parent = game.ReplicatedStorage

event.OnServerEvent:Connect(function(plr) local taps = plr.leaderstats.Taps taps.Value = taps.Value + 1 end)

game.Players.PlayerAdded:Connect(funtion(plr) local ls = Instance.new("Folder") ls.Name = "leaderstats" local menu = Instance.new ("IntValue", ls) menu.Name = "Taps" ls.Parent = plr end)

Can someone try find the problem pls?

3 answers

Log in to vote
0
Answered by
Xapelize 2658 Moderation Voter Community Moderator
3 years ago

Make sure you put this script on ServerScriptService.

game:GetService("Players").PlayerAdded:Connect(funtion(player)
    local leaderstats = Instance.new("Folder", player) 
    leaderstats.Name = "leaderstats" 

    local menu = Instance.new("IntValue", leaderstats) 
    menu.Name = "Taps"
end)

Don't put 2 different function in the same script, it's harder to find them. You should split the script 2 parts. So heres the another part.

Also, a note, you don't need to use RemoteEvent on the same script. RemoteEvent is used for sending information between server and client (yourself). Even you need to send them between scripts, you still can access the ClickDetector in one script. No RemoteEvent are needed.

What you are gonna do in the another script. Make this as a script and put it in ServerScriptService as well.

game:GetService("Players").PlayerAdded:Connect(function(player)
    wait()
    local ClickDetector = game.Workspace.Part.ClickDetector

    ClickDetector.MouseClick:Connect(function()
        player.leaderstats.Taps.Value = player.leaderstats.Taps.Value + 1
    end)
end)
Ad
Log in to vote
0
Answered by
MattVSNNL 620 Moderation Voter
3 years ago

Try this code out buddy!

Put this code in a script from serverscriptservice

game.Players.PlayerAdded:Connect(function(player)

    local leaderstats = Instance.new(¨Folder¨)
    leaderstats.Name = ¨leaderstats¨
    leaderstats.Parent = player

    local taps = Instance.new(¨IntValue¨)
    taps.Name = ¨Taps¨
    taps.Value = 0
    taps.Parent = leaderstats

end)
Log in to vote
0
Answered by
spectsy 16
3 years ago

I think that a leaderboard only "gets created" when the game has initiated, I don't think that you can make a new value in the middle of the game, roblox has already made the leaderstats. /shrug

Answer this question