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

Why is this script not changing the value?

I'm trying to change the speed you can click at depending on the amount of money (oofs) you have. This, however, is not working. It doesn't even do the prints.

game.Players.PlayerAdded:Connect(function()
	print("hi i exist")
	if oofs <= 99 then
		clickSpeed.Value = 1
		print(clickSpeed)
	elseif oofs >= rangeOne.Min and oofs <= rangeOne.Max then
		clickSpeed.Value = 0.9
		print(clickSpeed)
	elseif oofs >= rangeTwo.Min and oofs <= rangeTwo.Max then
		clickSpeed.Value = 0.8
		print(clickSpeed)
	end
end)


1 answer

If you are testing this in studio, then the local player will often exist before this script runs. To catch this, you can also go through every player already in game and run this function. Something like this:

local function Setup(player)
	print("hi i exist")
	if oofs <= 99 then
		clickSpeed.Value = 1
		print(clickSpeed)
	elseif oofs >= rangeOne.Min and oofs <= rangeOne.Max then
		clickSpeed.Value = 0.9
		print(clickSpeed)
	elseif oofs >= rangeTwo.Min and oofs <= rangeTwo.Max then
		clickSpeed.Value = 0.8
		print(clickSpeed)
	end
end

local playersInGame = game.Players:GetPlayers()
for i = 1, #playersInGame do
	Setup(playersInGame[i])
end
game.Players.PlayerAdded:Connect(Setup)

Note that this will run for every player entering the game - not just the local player, and so you should check how many oofs each player joining has.

3 comments

0

Got an error; Players.stupru.PlayerGui.ScreenGui.mainScript:16: attempt to compare userdata with number

0

There was an error with my script where I hadn't deleted the closing parentheses on line 13 when I copied your script, but other than that I just tried the code above myself and it works fine once I add variables for oofs, clickSpeed, rangeOne and rangeTwo. Can you post your updated script so I can see what might be causing the error?

0

ill just post another question on it and post my whole script including variables up to this point

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