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

Help with making this script only add 1 a random value and not all?

I am making a card game where player's card are based on the number a child in leaderstats, but my problem is that this script adds 1 to every value instead of only one random value. Here is the code:

script.Parent.MouseButton1Click:connect(function()
	wait(0.05)
	script.Parent.Selectable = false
	wait(1)
	local text = script.Parent.Message.Text
	text = "Randomizing Prize."
	wait(1)
	text = "Randomizing Prize.."
	wait(1)
	text = "Randomizing Prize..."
	wait(1)
	text = "Randomizing Prize."
	wait(1)
	text = "Randomizing Prize.."
	wait(1)
	text = "Randomizing Prize..."
	wait(1)
	text = "Randomizing Prize."
	wait(1)
	text = "Randomizing Prize.."
	wait(1)
	text = "Randomizing Prize..."
	wait(1)
	text = "Randomizing Prize."
	wait(1)
	text = "Randomizing Prize.."
	wait(1)
	text = "Randomizing Prize..."
	wait(1)
	text = "Randomizing Prize."
	wait(1)
	text = "Randomizing Prize.."
	wait(1)
	text = "Randomizing Prize..."
	wait(1)
	text = "Randomizing Prize."
	wait(1)
	text = "Randomizing Prize.."
	wait(1)
	text = "Randomizing Prize..."
	local children = game.Players.LocalPlayer.leaderstats:GetChildren()
for i = 1, #children do
    children[i].Value = children[i].Value + 1
end 
end)

5 comments

0

The for loop at the end adds 1 to each of the leaderstats

0

I don't know how to make it only choose one. That is the question.

0

Tell us which one you want to add to

0

A random child of leaderstats

0

use random.math

1 answer

If you are trying to add value to a certain number then you want to define the Value, For example; local TestValue = script.Parent This shows where the "TestValue" is and then you can add to it by doing something like this;

local TestValue = script.Parent -- change this to where TestValue is

game.Players.PlayerAdded:Connect(function(Plr)
	TestValue.Value = TestValue.Value + 1
end)

If you wanted it to add to a random Number/Int value then we use math.randomseed

In this case, do something like;

local children = game.Players.LocalPlayer.leaderstats:GetChildren()

for i = #children do
	local pick = math.randomseed(1, i)
	if pick == 1 then
		-- make whatever line add value
		if pick == 2 then
		-- ADD VALUE
	end
end

You should get the idea, anyway if I helped please accept answer :D

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