"Be online for 10 hours" task broken

I tested your script and it works. Since that part is functioning correctly, the issue may potentially lie within this script:

game.ReplicatedStorage.tasks.h2.OnServerEvent:Connect(function(player, newCoins)
	local taskk = player:WaitForChild("tasks")
	local taskk2 = saunat:FindFirstChild("ht2")
	wait(.5)
	taskk2.Value = newCoins
end)

This script locates here:

kuva
kuva

As I mentioned, the “allsaves” script notifies the datastore script when a specific value has changed and then saves the new value to the datastore. The reason it needs to inform the datastore about the change is that the “taskscript” is a local script.

I attempted to implement this system, but the issue remains the same:

local function updateHours2(value)
	wait(.5)

	ht2.Value += 1
	h2:FireServer(ht2.Value)
	local seconds = value 
	local hours = seconds / 3600 
	local formattedHours = string.format("%.1f h", hours) 
	return formattedHours
end

and

ht2.Changed:Connect(function()
	wait(.5)
...
	elseif hr2.Value == 5 then
		if ht2.Value >= 36000 then
			coin.Value = coin.Value + 1000000000
			coe:FireServer(coin.Value)
			hteht = 2 --this just tells, which textlabel shows the task
			hr2.Value = 0
			ht2.Value = 0
			wait()
			hdone = 'Be online for 10 hours' --this just tells player which task player completed
			done()-- this shows frame with the task what you have completed
			vaikeus = 3 -- "vaikeus" means "difficulty"
			t2.task2.Text = "x"
		else
			if vaikeus == 3 then

				t2.task2.Text = hourht2 .. "/ 10h"

			end
	
			hourht2 = updateHours2(ht2.Value)

		end
...
end)




if hr2.Value == 5 then
	hourht2 = updateHours2(ht2.Value)

	print("ht2 started")
end

Here is the whole code with the translations because I live in Finland and I like to use finnish words in the code. Because it’s too long and hard to read in here, I made a link. Here it is:

https://dpaste.org/6ejmy

Edit: This is annoying bug because it’s simple bug but hard to fix it. Hopefully we can find the solution for this problem

Also, if we can find a solution to this problem, I would like to give you some gems for this game. This task system will be a part of my game called ‘Extreme Sauna Simulator.’ Gems are genuinely rare in my game, and you can receive 1000 gems for free, only if you wish, and we can resolve this issue. I just don’t know how to thank you, so I’m offering this as a token of my appreciation.

btw make sure to add verification onserverevent , exploiter can abuse it by changing number

2k lines of code seems extremely unnecessary. There’s a lot of repetition within your code.

“But my code works, that’s the main thing”

If your code did work, this topic wouldn’t exist right? :slight_smile: the problem at hand would be resolved gradually, but you need to understand how impossible it becomes to manage such code once any issues (even the smallest) occur. If you ever need to improve anything, it becomes a big deal.

Also, for anyone outside your development circle (that is, us), reading the code and looking at ht1 hr2 mt3 mr1 looks absolutely the same.

I totally don’t mean to be rude here, but this method is actually an obfuscation technique used in many malware to avoid antivirus detection. I can share an example (video analysis educational only. No malware shared) here.

1 Like

Okay, I understand… and no, no, no… it’s nothing. I don’t mind if you say things like that. It’s good to express your own feelings about things and so on.

You are right, it may look like malware code, but honestly, I’m a bit lazy, so I use ht1, hr2… instead of the longer versions like hardtask1, hardrandom2. I also use shorter versions because I have many, many, many values in this task system, and it would take forever if I tried to make everything more organized (for example, by using longer variable names).

I’m really sorry if my code appears to be poorly structured and messy. I just don’t have much time to work on my game because I’m in a course where everyone is running their own company with a company project, and my project is this Roblox game. I have to finish it before the new year. I have eight more tasks to complete after this task system, and that’s why I’m rushing and things are getting messy.

Please, feel free to ask me anything, and I’ll provide answers. I just want to fix this annoying problem so I can finally make progress. And again… Sorry. My goal is to become one of the best and friendliest Roblox game developers ever. I don’t want to ruin that. Please try to understand.

I think you have identified the problem - it is here, I think:

game.ReplicatedStorage.tasks.h2.OnServerEvent:Connect(function(player, newCoins)
	local taskk = player:WaitForChild("tasks")
	local taskk2 = saunat:FindFirstChild("ht2")
	wait(.5)
	taskk2.Value = newCoins <-- HERE
end)

The server is updating the value to whatever newCoins is set to but this can/will happen some time after ht2 is updated on the client.

Look at it on a time line - this is a potential scenario that is likely happening:

  1. ht2 updated on client
  2. ht2 sent to server
  3. ht2 updated on client
  4. ht2 updated on server to value from #2 - now has a different value from #3 and fires the changed event on client!

Basically, you are asynchronously updating the same value at different times to different values and your changed event is handling all of them.

You aren’t going to like the answer to fix this - you just can’t do it this way. You have to change the value on the client OR on the server, not both. One of them has to be the “authority” on what the ht2 value “should be”.

Typically, the server should be the authority to avoid people hacking your game - any local scripts can be seen/modified by users (potentially). This is why the suggestion was made that your game will be easy to hack.

The code I posted above to track how long a player is in the game is all happening server-side so the server is the authority and an end user could never hack the value.

To fix your solution you would need to move the task handling server-side or at least do not change the value on both client and server.

Last note: I completely understand doing things fast. But there is a right way and a wrong way to do things fast in software development. Often when starting out, people just don’t know the right way and the wrong way :slight_smile: What I mean by that is, as one of the posters above is trying to highlight, is that you say your code looks like this because you want to do it fast and yet a big factor in trying to figure out the problem here is due to the way the code is written which is slowing you down.

It is a classic mistake for inexperienced devs - they think they are moving fast only to discover that what is fast in the first day/week/month slows down to a crawl in “phase 2” which is actually making it work right long term, fixing a bug or when changing it later.

It is all about making the “right” tradeoffs to move fast. And that is simply hard to know how to do unless you have years of dev experience. About all I can offer here is to take a different approach when on your next project or when you have time. Slowing down early and making the right design decisions can save you an enormous amount of time later in a project.

1 Like

But writing cleaner code takes lesser time… and it is fixable too… This is almost at the point of unfixable :frowning: especially, by someone outside your development circle.

Note that the video I shared analyses an actual piece of malware (not Roblox plugin kind) so that’s something to look out for :sweat_smile: , overall though that video is quite fun and you should watch it in your free time.

Next point, labelling your variables. You gather many variable values using : FindFirstChilsWhich or WaitForChild so we have no idea what those instances are or what class they are of.

My solution, would be to redo it completely :frowning:

1 Like

Have you looked at the entire file? Cause I believe OP has good potential but lacks guidance. I am busy (full time) with something else and hence cannot commit to guide them so.

Yes, I did. Lot of opportunity for improvement :slight_smile:

That said, the issue & video posted originally is easily explained if the ht2 value is being updated on both the client and server (and the client is telling the server to update it when it updates). In the post showing game.ReplicatedStorage.tasks.h2.OnServerEvent:Connect it looks like this is exactly what is being done. Simplest explanation and all that…

I’ve also got a FT job doing dev/mgr stuff with other devs that have lots of potential so I tend to spend most of my time there since they pay me :smiley:

1 Like

Ugh… It will take forever… But if you relaly want me to do it then I’ll do it. But only if you can help me after that. Okay??? I’ll try to find solutions myself and if I cannot fix the problem by myself, I will change them (for example ht1 into hardtask1).

I’ve also got a FT job doing dev/mgr stuff with other devs that have lots of potential so I tend to spend most of my time there since they pay me

congratulations! :3

local Players = game:GetService("Players");
local DataStoreService = game:GetService("DataStoreService");

local TimePlayed = DataStoreService:GetDataStore("TimePlayed");
local TimeJoined = DataStoreService:GetDataStore("TimeJoined")

Players.PlayerAdded:Connect(function(player)
	local timePlayed = TimePlayed:GetAsync("UserData"..player.UserId);
	if (timePlayed == 0 or timePlayed == nil) then
		TimeJoined:SetAsync("UserData", os.time(), player.UserId);
		TimePlayed:SetAsync("UserData", 0, player.UserId);
		timePlayed = 0;
	end;
	local playTime = Instance.new("IntValue");
	playTime.Parent = player;
	playTime.Value = 0;
	playTime.Name = "playTime";
	
	task.spawn(function()
		while task.wait(1) do
			playTime.Value += 1;
			if (playTime.Value + timePlayed >= 36000) then
				print("played for 10 hours")
			end;
		end;
	end);
end);
1 Like

FINALLY IT’S FIXED!

I made the server script and the timer system is now in there. My task script changes the text always when HardTask1 (old name ht1) value changes and when the value is over 36000, It gives you reward and changes the task.

Here is the new server script timer system:

local Players = game:GetService("Players")

local function updateHours(HardRandom, HardTask1)

	local isCounting = true

	HardRandom.Changed:Connect(function()
		if HardRandom.Value == 5 then
			isCounting = true
		else
			isCounting = false
		end
	end)

	while true do
		if isCounting then
			
			local success, error = pcall(function()
				HardTask1.Value = HardTask1.Value + 1
			end)
			if not success then
				warn("Error in updateHours: " .. error)
			end
		end
		wait(1)
	end
end

Players.PlayerAdded:Connect(function(player)

	local HardRandom = player:WaitForChild("tasks"):FindFirstChild("hraha")
	local HardTask1 = player:WaitForChild("tasks"):FindFirstChild("ht1")

	if HardRandom.Value == 5 then
	
		updateHours(HardRandom, HardTask1)
	end
end)

Also, I believe that I have all your names, and now, only if you ever decide to play my game called ‘Extreme Sauna Simulator’ when the new update is released, you will receive 1000 gems for free, as I promised. Thanks to you all! :).

Hey. If you think HardTask1 is a “long variable name”, please take a look at this piece I found while casually scrolling


(Originally from John Hammond’s Video)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.