How To Make More Then One Function Work

I am trying to make a script where if you touch a part UI come up. I have this for all of the parts but only the first function works. How do i make all of them work

local Animator = game.Workspace.Map.Jobs.HitBoxes:WaitForChild("Animator")
local Artist = game.Workspace.Map.Jobs.HitBoxes:WaitForChild("Artist")
local Builder = game.Workspace.Map.Jobs.HitBoxes:WaitForChild("Builder")
local ClothingDesigner = game.Workspace.Map.Jobs.HitBoxes:WaitForChild("ClothingDesiner")
local Composer = game.Workspace.Map.Jobs.HitBoxes:WaitForChild("Composer")
local Modeler = game.Workspace.Map.Jobs.HitBoxes:WaitForChild("Modeler")
local Scripter = game.Workspace.Map.Jobs.HitBoxes:WaitForChild("Scripter")
local UIDesigner= game.Workspace.Map.Jobs.HitBoxes:WaitForChild("UIDesigner")

Animator.Touched:Connect(function(Hit)
	if Hit.Parent:FindFirstChild("Humanoid") then
		script.Parent.Parent.JobUI.AnimatorFrame.Visible = true
		repeat task.wait() until (Animator.Position - Hit.Parent.HumanoidRootPart.Position).magnitude >= 12
		script.Parent.Parent.JobUI.AnimatorFrame.Visible = false
	end
end)

Artist.Touched:Connect(function(Hit)
	if Hit.Parent:FindFirstChild("Humanoid") then
		script.Parent.Parent.JobUI.ArtistFrame.Visible = true
		repeat task.wait() until (Animator.Position - Hit.Parent.HumanoidRootPart.Position).magnitude >= 12
		script.Parent.Parent.JobUI.ArtistFrame.Visible = false
	end
end)

Builder.Touched:Connect(function(Hit)
	if Hit.Parent:FindFirstChild("Humanoid") then
		script.Parent.Parent.JobUI.BuilderFrame.Visible = true
		repeat task.wait() until (Animator.Position - Hit.Parent.HumanoidRootPart.Position).magnitude >= 12
		script.Parent.Parent.JobUI.BuilderFrame.Visible = false
	end
end)

ClothingDesigner.Touched:Connect(function(Hit)
	if Hit.Parent:FindFirstChild("Humanoid") then
		script.Parent.Parent.JobUI.ClothingFrame.Visible = true
		repeat task.wait() until (Animator.Position - Hit.Parent.HumanoidRootPart.Position).magnitude >= 12
		script.Parent.Parent.JobUI.ClothingFrame.Visible = false
	end
end)

Composer.Touched:Connect(function(Hit)
	if Hit.Parent:FindFirstChild("Humanoid") then
		script.Parent.Parent.JobUI.ComposerFrame.Visible = true
		repeat task.wait() until (Animator.Position - Hit.Parent.HumanoidRootPart.Position).magnitude >= 12
		script.Parent.Parent.JobUI.ComposerFrame.Visible = false
	end
end)

Modeler.Touched:Connect(function(Hit)
	if Hit.Parent:FindFirstChild("Humanoid") then
		script.Parent.Parent.JobUI.ModelerFrame.Visible = true
		repeat task.wait() until (Animator.Position - Hit.Parent.HumanoidRootPart.Position).magnitude >= 12
		script.Parent.Parent.JobUI.ModelerFrame.Visible = false
	end
end)

Scripter.Touched:Connect(function(Hit)
	if Hit.Parent:FindFirstChild("Humanoid") then
		script.Parent.Parent.JobUI.ScripterFrame.Visible = true
		repeat task.wait() until (Animator.Position - Hit.Parent.HumanoidRootPart.Position).magnitude >= 12
		script.Parent.Parent.JobUI.ScripterFrame.Visible = false
	end
end)

UIDesigner.Touched:Connect(function(Hit)
	if Hit.Parent:FindFirstChild("Humanoid") then
		script.Parent.Parent.JobUI.UIDFrame.Visible = true
		repeat task.wait() until (Animator.Position - Hit.Parent.HumanoidRootPart.Position).magnitude >= 12
		script.Parent.Parent.JobUI.UIDFrame.Visible = false
	end
end)
1 Like

Are there any errors outputed?

1 Like

None---------------------------

1 Like

Send me the explorer tab and I might be able to help.

Screenshot 2023-08-15 at 13.47.23
Screenshot 2023-08-15 at 13.47.41

and the script is in StarterGui

Is the script literally just in startergui?

Ya it only works in there-------

Is the “JobUI” located inside StarterGui?

Yes it is--------------------------------

UIDesigner.Touched:Connect(function(Hit)
spawn(function()
	if Hit.Parent:FindFirstChild("Humanoid") then
		script.Parent.Parent.JobUI.UIDFrame.Visible = true
		repeat task.wait() until (Animator.Position - Hit.Parent.HumanoidRootPart.Position).magnitude >= 12
		script.Parent.Parent.JobUI.UIDFrame.Visible = false
	end
end)
end)

Beatifully written code :clap:

-Extensive use of variables for clarity :white_check_mark:
-No trace of redundancy of code :white_check_mark:
-Good spacing :white_check_mark:

Honestly impeccable. 10/10. Can’t wait to see where your talent takes you!

1 Like

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