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

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

Asked by 10 years ago
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?

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? duckwit 1404 — 10y
0
yes rabidhalofan12345 55 — 10y

2 answers

Log in to vote
0
Answered by 10 years ago

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)
0
still dosent work :/ rabidhalofan12345 55 — 10y
Ad
Log in to vote
-2
Answered by 10 years ago

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.

0
im trying to do it to a person not a certain person rabidhalofan12345 55 — 10y
0
Oh, okay but why did you downvote? I was only trying to help. Darknesschaos 0 — 10y

Answer this question