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

How would I get this value to apply to only one person?

local a = 0
local equip = 0
CGUI = script.Parent.Parent.Classes.Backing

CGUI.Swordsman.MouseButton1Click:connect(function()
	equip = a + 1
	CGUI.Value.Value = equip
	CGUI.Swordsman.TL.Text = "Selected"
		for _,Player in pairs(game.Players:GetPlayers()) do
        if Player:FindFirstChild("leaderstats") then
            Player.leaderstats.value.Value = script.Parent.Backing.Value.Value
		end
	end
end)

When someone presses a gui button it gives the person a leaderstat value of 1, but when someone presses the button everybody gets a leaderstat value of 1. How would I only apply the value to the person who clicked the button?

2 comments

0

When this button is clicked, do you want the leaderstat value of the player who clicked it to go up, or just that of a random player?

0

yes

2 answers

The easiest way to do it is to add a bool value to keep track if you gave it to one person.

local a = 0
local equip = 0
CGUI = script.Parent.Parent.Classes.Backing

local GaveToOnePerson = false

CGUI.Swordsman.MouseButton1Click:connect(function()
	if GaveToOnePerson == false then
		GaveToOnePerson = true
		equip = a + 1
		CGUI.Value.Value = equip
		CGUI.Swordsman.TL.Text = "Selected"
		for _,Player in pairs(game.Players:GetPlayers()) do
			if Player:FindFirstChild("leaderstats") then
				Player.leaderstats.value.Value = script.Parent.Backing.Value.Value
			end
		end
	end
end)

1 comment

0

still dosent work :/

Try adding the player's name within the loop so it should look like this:

local a = 0
local equip = 0
CGUI = script.Parent.Parent.Classes.Backing

CGUI.Swordsman.MouseButton1Click:connect(function()
    equip = a + 1
    CGUI.Value.Value = equip
    CGUI.Swordsman.TL.Text = "Selected"
        for _,Player in pairs(game.Players:GetPlayers()) do
        if Player:FindFirstChild("leaderstats") and Player.Name = "" -- Put the player's name here
 then
            Player.leaderstats.value.Value = script.Parent.Backing.Value.Value
        end
    end
end)

This will find the Player's leaderstats AND find the Player's name.

2 comments

0

im trying to do it to a person not a certain person

0

Oh, okay but why did you downvote? I was only trying to help.

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