Job script isn't working days after it was?

So I have this job script that if you cleaned all of the footprints on the ground, which is controlled using a buttongui that, if you have the tool “broom” in your hand it allows you to clean. It worked where once you cleaned all the footprints, it gave you 8 dollars, all was good, and if you didnt clean them all, it would tell you to get back to work. The way you check in to get the 8 dollars is yet another surface click, that when clicked is sent to a client in the startergui, that sends a remote event to a server script, giving the gui to the player. Heres the part of the script that determines if the player has done the job or not.

–// Client

local Player = game.Players.LocalPlayer

local Character = Player.Character or Player.CharacterAdded:Wait()

local Camera = game.Workspace.CurrentCamera

local FindTool = Player.Backpack:FindFirstChild(“Broom”) or Character:FindFirstChild(“Broom”)

–// GUIs

–// Main

repeat wait()

Camera.CameraType = Enum.CameraType.Custom

until Camera.CameraType == Enum.CameraType.Custom

Camera.CameraType = Enum.CameraType.Custom

Character.UpperTorso.Anchored = true

script.Parent.Dialogue.Visible = true

script.Parent.Dialogue.CharText.Text = “H”

wait(0.05)

script.Parent.Dialogue.CharText.Text = “He”

wait(0.05)

script.Parent.Dialogue.CharText.Text = “Hel”

wait(0.05)

script.Parent.Dialogue.CharText.Text = “Hell”

wait(0.05)

script.Parent.Dialogue.CharText.Text = “Hello”

wait(0.05)

script.Parent.Dialogue.CharText.Text = “Hello!”

wait(0.05)

script.Parent.Dialogue.CharText.Text = “Hello! H”

wait(0.05)

script.Parent.Dialogue.CharText.Text = “Hello! Ho”

wait(0.05)

script.Parent.Dialogue.CharText.Text = “Hello! How”

wait(0.05)

script.Parent.Dialogue.CharText.Text = “Hello! How a”

wait(0.05)

script.Parent.Dialogue.CharText.Text = “Hello! How ar”

wait(0.05)

script.Parent.Dialogue.CharText.Text = “Hello! How are”

wait(0.05)

script.Parent.Dialogue.CharText.Text = “Hello! How are y”

wait(0.05)

script.Parent.Dialogue.CharText.Text = “Hello! How are yo”

wait(0.05)

script.Parent.Dialogue.CharText.Text = “Hello! How are you”

wait(0.05)

script.Parent.Dialogue.CharText.Text = “Hello! How are you?”

wait(0.05)

script.Parent.Dialogue.CharText.Text = “Hello! How are you? W”

wait(0.05)

script.Parent.Dialogue.CharText.Text = “Hello! How are you? Wh”

wait(0.05)

script.Parent.Dialogue.CharText.Text = “Hello! How are you? Wha”

wait(0.05)

script.Parent.Dialogue.CharText.Text = “Hello! How are you? What”

wait(0.05)

script.Parent.Dialogue.CharText.Text = “Hello! How are you? What w”

wait(0.05)

script.Parent.Dialogue.CharText.Text = “Hello! How are you? What wo”

wait(0.05)

script.Parent.Dialogue.CharText.Text = “Hello! How are you? What wou”

wait(0.05)

script.Parent.Dialogue.CharText.Text = “Hello! How are you? What woul”

wait(0.05)

script.Parent.Dialogue.CharText.Text = “Hello! How are you? What would”

wait(0.05)

script.Parent.Dialogue.CharText.Text = “Hello! How are you? What would y”

wait(0.05)

script.Parent.Dialogue.CharText.Text = “Hello! How are you? What would yo”

wait(0.05)

script.Parent.Dialogue.CharText.Text = “Hello! How are you? What would you”

wait(0.05)

script.Parent.Dialogue.CharText.Text = “Hello! How are you? What would you l”

wait(0.05)

script.Parent.Dialogue.CharText.Text = “Hello! How are you? What would you li”

wait(0.05)

script.Parent.Dialogue.CharText.Text = “Hello! How are you? What would you lik”

wait(0.05)

script.Parent.Dialogue.CharText.Text = “Hello! How are you? What would you like”

wait(0.05)

script.Parent.Dialogue.CharText.Text = “Hello! How are you? What would you like?”

wait(2)

if Player.Backpack:FindFirstChild(“Broom”) or Character:FindFirstChild(“Broom”) and game.Workspace:WaitForChild(“FootClean1”).Part2:FindFirstChild(“Decal”).Transparency == 0.9 and game.Workspace:WaitForChild(“FootClean2”).Part2:FindFirstChild(“Decal”).Transparency == 0.9 and game.Workspace:WaitForChild(“FootClean3”).Part2:FindFirstChild(“Decal”).Transparency == 0.9 then

script.Parent.Response1.Visible = true

script.Parent.Response2JobAdditionSucess.Visible = true

print(“FINISHED”)

else

if Player.Backpack:FindFirstChild(“Broom”) or Character:FindFirstChild(“Broom”) and game.Workspace:WaitForChild(“FootClean1”).Part2.Decal.Transparency == 0 and game.Workspace.FootClean2.Part2.Decal.Transparency == 0.9 and game.Workspace.FootClean3.Part2.Decal.Transparency == 0 then

script.Parent.Response1.Visible = true

script.Parent.Response2JobAddition.Visible = true

print(“Not Finished”)

else

if Player.Backpack:FindFirstChild(“Broom”) or Character:FindFirstChild(“Broom”) and game.Workspace:WaitForChild(“FootClean1”).Part2.Decal.Transparency == 0.9 and game.Workspace.FootClean2.Part2.Decal.Transparency == 0 and game.Workspace.FootClean3.Part2.Decal.Transparency == 0 then

script.Parent.Response1.Visible = true

script.Parent.Response2JobAddition.Visible = true

print(“Not Finished”)

else

if Player.Backpack:FindFirstChild(“Broom”) or Character:FindFirstChild(“Broom”) and game.Workspace:WaitForChild(“FootClean1”).Part2.Decal.Transparency == 0.9 and game.Workspace.FootClean2.Part2.Decal.Transparency == 0.9 and game.Workspace.FootClean3.Part2.Decal.Transparency == 0 then

script.Parent.Response1.Visible = true

script.Parent.Response2JobAddition.Visible = true

print(“Not Finished”)

else

if Player.Backpack:FindFirstChild(“Broom”) or Character:FindFirstChild(“Broom”) and game.Workspace:WaitForChild(“FootClean1”).Part2.Decal.Transparency == 0 and game.Workspace.FootClean2.Part2.Decal.Transparency == 0.9 and game.Workspace.FootClean3.Part2.Decal.Transparency == 0.9 then

script.Parent.Response1.Visible = true

script.Parent.Response2JobAddition.Visible = true

print(“Not Finished”)

else

if Player.Backpack:FindFirstChild(“Broom”) or Character:FindFirstChild(“Broom”) and game.Workspace:WaitForChild(“FootClean1”).Part2.Decal.Transparency == 0 and game.Workspace.FootClean2.Part2.Decal.Transparency == 0 and game.Workspace.FootClean3.Part2.Decal.Transparency == 0 then

script.Parent.Response1.Visible = true

script.Parent.Response2JobAddition.Visible = true

print(“Not Finished”)

else

if Player.Backpack:FindFirstChild(“Broom”) or Character:FindFirstChild(“Broom”) and game.Workspace:WaitForChild(“FootClean1”).Part2.Decal.Transparency == 0 and game.Workspace.FootClean2.Part2.Decal.Transparency == 0 and game.Workspace.FootClean3.Part2.Decal.Transparency == 0.9 then

script.Parent.Response1.Visible = true

script.Parent.Response2JobAddition.Visible = true

print(“Not Finished”)

else

if not Player.Backpack:FindFirstChild(“Broom”) or Character:FindFirstChild(“Broom”) then

script.Parent.Response1.Visible = true

script.Parent.Response2.Visible = true

print(“Not Started”)

1 Like

This isn’t answering your question specifically, but it could help clean your code so a problem is easier to identify.

You seem to have manually written out the text appearing on the screen. Could I suggest that instead of these 20+ lines, you do something like:

local stringText = "Hello! How are you? What would you like?"
-- define the string to show the player

for i = 1, #stringText do -- loop through the length of the string
    script.Parent.Dialogue.CharText.Text = string.sub(stringText, 1, i) -- set the text to be the partial string
    wait(0.05)
end

Using loops to write less lines will make it much easier to find problems and edit your code in the future!

4 Likes

I will test this out, thank you for helping me on this as it is quiet annoying having it take up so much room and having to write it out.

1 Like

I had to format all your code correctly to find the problem, I think. I also added a little for loop for the typewriter effect you were going for that spanned maybe half the page. @mario118118 already pointed this out though!

--// Client

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Camera = game.Workspace.CurrentCamera
local FindTool = Player.Backpack:FindFirstChild("Broom") or Character:FindFirstChild("Broom")

--// GUIs

--// Main
repeat 
	wait()
	Camera.CameraType = Enum.CameraType.Custom
until Camera.CameraType == Enum.CameraType.Custom

Camera.CameraType = Enum.CameraType.Custom
Character.UpperTorso.Anchored = true
script.Parent.Dialogue.Visible = true

local str = "Hello! How are you? What would you like?"

for i = 1, #str - 1 do
	script.Parent.Dialogue.CharText = str:sub(1,i)
	wait(0.05)
end

script.Parent.Dialogue.CharText = str

wait(2)

if 
	Player.Backpack:FindFirstChild("Broom") or 
	Character:FindFirstChild("Broom") and 
	game.Workspace:WaitForChild("FootClean1").Part2:FindFirstChild("Decal").Transparency == 0.9 and 
	game.Workspace:WaitForChild("FootClean2").Part2:FindFirstChild("Decal").Transparency == 0.9 and 
	game.Workspace:WaitForChild("FootClean3").Part2:FindFirstChild("Decal").Transparency == 0.9 
then

	script.Parent.Response1.Visible = true
	script.Parent.Response2JobAdditionSucess.Visible = true
	print("FINISHED")

else
	if 
		Player.Backpack:FindFirstChild("Broom") or 
		Character:FindFirstChild("Broom") and 
		game.Workspace:WaitForChild(“FootClean1”).Part2.Decal.Transparency == 0.9 and 
		game.Workspace.FootClean2.Part2.Decal.Transparency == 0 and 
		game.Workspace.FootClean3.Part2.Decal.Transparency == 0 
	then

		script.Parent.Response1.Visible = true
		script.Parent.Response2JobAddition.Visible = true
		print(“Not Finished”)
	else
		if 
			Player.Backpack:FindFirstChild(“Broom”) or 
			Character:FindFirstChild(“Broom”) and
			game.Workspace:WaitForChild("FootClean1").Part2.Decal.Transparency == 0.9 and 
			game.Workspace.FootClean2.Part2.Decal.Transparency == 0.9 and 
			game.Workspace.FootClean3.Part2.Decal.Transparency == 0 
		then

			script.Parent.Response1.Visible = true
			script.Parent.Response2JobAddition.Visible = true
			print("Not Finished")

		else
			if 
				Player.Backpack:FindFirstChild("Broom") or 
				Character:FindFirstChild("Broom") and 
				game.Workspace:WaitForChild("FootClean1").Part2.Decal.Transparency == 0 and 
				game.Workspace.FootClean2.Part2.Decal.Transparency == 0.9 and 
				game.Workspace.FootClean3.Part2.Decal.Transparency == 0.9 
			then

				script.Parent.Response1.Visible = true
				script.Parent.Response2JobAddition.Visible = true
				print("Not Finished")

			else

				if 
					Player.Backpack:FindFirstChild("Broom") or 
					Character:FindFirstChild("Broom") and 
					game.Workspace:WaitForChild("FootClean1").Part2.Decal.Transparency == 0 and 
					game.Workspace.FootClean2.Part2.Decal.Transparency == 0 and 
					game.Workspace.FootClean3.Part2.Decal.Transparency == 0 
				then

					script.Parent.Response1.Visible = true
					script.Parent.Response2JobAddition.Visible = true
					print("Not Finished")

				else
					if 
						Player.Backpack:FindFirstChild("Broom") or 
						Character:FindFirstChild("Broom") and 
						game.Workspace:WaitForChild("FootClean1").Part2.Decal.Transparency == 0 and 
						game.Workspace.FootClean2.Part2.Decal.Transparency == 0 and 
						game.Workspace.FootClean3.Part2.Decal.Transparency == 0.9 
					then

						script.Parent.Response1.Visible = true
						script.Parent.Response2JobAddition.Visible = true
						print("Not Finished")
					else
						if 
							not Player.Backpack:FindFirstChild("Broom") or 
							Character:FindFirstChild("Broom") 
						then

							script.Parent.Response1.Visible = true
							script.Parent.Response2.Visible = true
							print("Not Started")

By the way, you can create code blocks using three backticks or squigglies:

Input:
```
--code here
```

This works too:
~~~
--code here
~~~

Output:

--code here

So:

  1. Please explain what went wrong and how it went wrong, read the about page on this category for more info on how to format posts here. Give tracebacks from output, error messages, etc.

  2. Using elseifs instead of else ifs will save so much tab space. Before that though, you should use smarter if statements. Click the arrow thing below for some useful pointers (obviously).

If statement tips

For example, if you know that Response1 will always show no matter which statement is true, put it outside the statement as a whole.

So instead of this:

if Condition then
	
	Response1.Visible = true
	DoSomething()

else

	Response1.Visible = true
	DoSomethingElse()

end

Do this:

Response1.Visible = true

if Condition then

	DoSomething()

else

	DoSomethingElse()

end

And if you are finding you want to achieve the same code from multiple criteria, at least try to combine it all into one singular condition.

So instead of this:

if Condition1 and Condition2 then

	DoSomething()

elseif Condition3 and Condition4 then

	DoSomething()

else

	DoSomethingElse()

end

Do this:

if (Condition1 and Condition2) or (Condition3 and Condition4) then

	DoSomething()

else

	DoSomethingElse()

end

Also, if you have one all-encompassing condition that is used between many if statements, it is often simpler to nest if statements with that all-encompassing condition as the preceding one:

Instead of this:

if HasBroom and Condition1 then

	DoSomething()

elseif HasBroom and Condition2 then

	DoSomethingElse()

else

	DoSomethingElseElse()

end

Do this:

if HasBroom then
	if Condition1 then
		
		DoSomething()

	elseif Condition2 then

		DoSomethingElse()

	end
else

	DoSomethingElseElse()

end

I would use this mainly just for organization and to compartmentalize use cases so that I don’t get overwhelmed.


You should combine all these tips to simplify your if statement drastically, the elseif tip will help with just keeping your code from trailing too far off the right. While writing this, I shortened your if statement to an astonishing twelve lines. I wrote it here using pseudocode:

Response1.Visible = true
if HasBroom then
	Response2JobAddition.Visible = true
	if Foot1isClean and Foot2isClean and isFoot3isClean then
		print("FINISHED")
	else
		print("Not Finished")
	end
else
	Response2.Visible = true
	print("Not Started")
end
  1. I would use flags to know when a footprint is gone instead of checking the decal’s transparency directly by using events. A good use case for yours would be connecting a GetPropertyChangedSignal event to your decals in question and comparing the transparency there.

  2. Checking floating point numbers with == is never ever a good idea, you always need to at least include space for error using inequalities or clamping.

e.g.

So instead of this:

if Transparency == 0.9 then

	DoSomething()

end

Do this:

if Transparency > 0.89 and Transparency < 0.91 then

	DoSomething()

end

Or this:

if math.clamp(Transparency, 0.89, 0.91) == Transparency then

	DoSomething()

end

The exceptions are integers and floating point numbers of base 2, which can be written as a / 2^b, where a and b are integers.

2 Likes

Thank you for taking the time to try and help me with this issue, although this script has not worked, I still appreciate you for trying.

1 Like