Ad
Log in to vote
1

How would I make it so that my Script creates a leaderboard so it can add 1 to one of its stats?

Asked by 1 year ago
game.Players.PlayerAdded:Connect(function(plr)
    local stats = Instance.new("Folder")
    stats.Name = "leaderstats"
    stats.Parent = plr

    local DP = Instance.new("IntValue")
    DP.Name = "Points"
    DP.Parent = stats

    local DR = Instance.new("IntValue")
    DR.Name = "Dice Rolls"
    DR.Parent = stats

end)

local Player = game.Players.LocalPlayer
local DR = Instance.new("IntValue")
script.Parent.MouseButton1Click:Connect(function()
    Player.leaderstats["Dice Rolls"].Value += 1
    script.Parent.Visible = false
    script.Parent.Parent.StClOnRB.Visible = true
wait(2.5)
    script.Parent.Visible = true
    script.Parent.Parent.StClOnRB.Visible = false
    script.Parent.Parent.StClOnRB.Selectable = false
end)

What I want the script to do: Make leaderstats so it can add 1 to DR on click of its parent ImageButton.

What the script does: Keep it from being clicked over and over.

The Script is inside an ImageButton that is inside a ScreenGui inside StarterGui.

0
wait, is this a server script or local? and where is it located raid6n 2326 — 1y
0
wait, is this a server script or local? and where is it located raid6n 2326 — 1y
1
it used to be a script but i changed it to a local script since you wnated to use a local script Jakob_Cashy 67 — 1y

1 answer

Log in to vote
1
Answered by
raid6n 2326 Moderation Voter Community Moderator
1 year ago
Edited 1 year ago

Hey! I believe I found your issue. The problem is that you're changing the leader stats value in a local script.

Before we begin, please make a RemoteEvent in ReplicatedStorage, and call it RemoteEvent

The local script:

script.Parent.MouseButton1Click:Connect(
    function()
        local player = game.Players.LocalPlayer
        local remoteEvent = game.ReplicatedStorage.RemoteEvent
        remoteEvent:FireServer(player)
        script.Parent.Visible = false
        script.Parent.Parent.StClOnRB.Visible = true
        wait(2.5)
        script.Parent.Visible = true
        script.Parent.Parent.StClOnRB.Visible = false
        script.Parent.Parent.StClOnRB.Selectable = false
    end
)

a server script in serverscriptservice

game.Players.PlayerAdded:Connect(
    function(plr)
        local stats = Instance.new("Folder")
        stats.Name = "leaderstats"
        stats.Parent = plr

        local DP = Instance.new("IntValue")
        DP.Name = "Points"
        DP.Parent = stats

        local DR = Instance.new("IntValue")
        DR.Name = "Dice Rolls"
        DR.Parent = stats
    end
)
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(
    function(player)
        player.leaderstats["Dice Rolls"].Value += 1
    end
)

1
cool it works Jakob_Cashy 67 — 1y
1
thanks for the help Jakob_Cashy 67 — 1y
Ad

Answer this question