Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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.

3 comments

0

wait, is this a server script or local? and where is it located

0

wait, is this a server script or local? and where is it located

1

it used to be a script but i changed it to a local script since you wnated to use a local script

1 answer

✓ Accepted answer

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
)

2 comments

1

cool it works

1

thanks for the help

This discussion is preserved as it was. New answers, comments, and votes are closed.