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?
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)
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.