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

Value change won't work

I am making a Cookie Clicker game, and I am trying to make it so if a Player has 100 Cookies, they can buy an Option to get automatic cookies, but I am having troubles on it. The first line has an error, for the "if script.Parent.Parent.Parent.Cookies.Number.Value = 100 then" part. Here is the script:

function onClicked()
	if script.Parent.Parent.Parent.Cookies.Number.Value = 100 then
	while true do
		script.Parent.Parent.Parent.Cookies.Text = script.Parent.Number.Value
	script.Parent.Parent.Parent.CPS.Number.Value = script.Parent.Parent.Parent.CPS.Number.Value + 0.3
	script.Parent.Parent.Parent.CPS.Text = script.Parent.Parent.Parent.CPS.Number.Value
end
script.Parent.MouseButton1Click:connect(Click)

1 comment

0

It won't work

2 answers

Here, let me fix this up:

function onClicked()
	if script.Parent.Parent.Parent.Cookies.Number.Value == 100 then
		while true do
			script.Parent.Parent.Parent.Cookies.Text = tostring(script.Parent.Number.Value)
			script.Parent.Parent.Parent.CPS.Number.Value = script.Parent.Parent.Parent.CPS.Number.Value + 0.3
			script.Parent.Parent.Parent.CPS.Text = tostring(script.Parent.Parent.Parent.CPS.Number.Value)
			wait()
		end
	end
end

script.Parent.MouseButton1Click:connect(onClicked)

Make sure your CPS value isn't an intvalue because integers don't go into decimals also == 100 not = 100 == means "is equal to" as a question = means simply put "is" also fix on your script

function onClicked()
    if script.Parent.Parent.Parent.Cookies.Number.Value == 100 then
		while true do
			wait(1)
			script.Parent.Parent.Parent.Cookies.Text = script.Parent.Number.Value
			script.Parent.Parent.Parent.CPS.Number.Value = script.Parent.Parent.Parent.CPS.Number.Value + 0.3
			script.Parent.Parent.Parent.CPS.Text = script.Parent.Parent.Parent.CPS.Number.Value
		end
	end
end
script.Parent.MouseButton1Click:connect(Click)

1 comment

0

personally i'd do wait(3) then change 0.3 to 1 just to keep stuff at integers

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