How do I send a signal to another script to do something?

What’re you trying to do?
I want to send a signal from one script to another. Want I’m doing is whenever you touch the part it places a billboard GUI above your head. There’s also another part that removes all the current billboard GUI’s on you.

What’s the problem?
The problem is whenever you touch the part that gives you the billboard GUI it only gives it to you once because of the debounce. Whenever you remove the billboard GUI the other part that gives you the billboard GUI doesn’t give another one. You may ask why don’t I just remove the debounce? If I did that it would create a bunch of the billboard GUI’s, I only want it to give you one. It’s kind of hard to explain.

What have I tried?
I couldn’t think of anything to do, I’m completely stuck.

The script that gives the billboard GUI

local InUse = false

part.Touched:Connect(function(hit)
	if InUse == false then
		
	InUse = true
	if hit.Parent:FindFirstChild("Humanoid")then
		local rep = game:GetService("ReplicatedStorage")
		local OwnerBill = rep:WaitForChild("OwnerGUI")
		
		local OwnerBillClone = OwnerBill:Clone()
			OwnerBillClone.Parent = hit.Parent.Head
			end
	end
end)

The script that removes the billboard GUI

local part = script.Parent

part.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local head = hit.Parent.Head
		if head:FindFirstChild("OwnerGUI") then
			local owner = head.OwnerGUI
			owner:Destroy()
		end
	end
end)

This the whole thing
image

2 Likes

The script that gives the billboard GUI

local InUse = false

part.Touched:Connect(function(hit)
	if InUse == false then
		
	InUse = true
	if hit.Parent:FindFirstChild("Humanoid") then
		local rep = game:GetService("ReplicatedStorage")
		local OwnerBill = rep:WaitForChild("OwnerGUI")
		
		local OwnerBillClone = OwnerBill:Clone()
			OwnerBillClone.Parent = hit.Parent.Head
			end
	end
end)

should be changed to

local InUse = false

part.Touched:Connect(function(hit)
	if InUse == false then
		
	InUse = true
	if hit.Parent:FindFirstChild("Humanoid") and hit.Parent:Head:FindFirstChild("OwnerBillClone") == nil then
		local rep = game:GetService("ReplicatedStorage")
		local OwnerBill = rep:WaitForChild("OwnerGUI")
		
		local OwnerBillClone = OwnerBill:Clone()
			OwnerBillClone.Parent = hit.Parent.Head
wait(5)
InUse = false
    			end
    	end
    end)
2 Likes

Thanks but I don’t really understand how that works, the line:

if hit.Parent:FindFirstChild("Humanoid") and hit.Parent:Head:FindFirstChild("OwnerBillClone") == nil then

I don’t understand because the variable OwnerBillClone hasn’t been defined yet so how would that work?

That’s a string name, not a variable name. The script is checking to see if there is a billboard GUI named OwnerBillClone that exists at the target, and does nothing if so.

1 Like

What’s the target in the script?

hit.Parent.Head:FindFirstChild("OwnerBillClone") == nil

  1. In the head of the target model that touched this brick, run the function FindFirstChild with the argument OwnerBillClone.
  2. the function FindFirstChild looks for any descendents (also called children) of the target (in this case, hit.Parent.Head, or the head of your humanoid) and will return truthy with the first child in the list with a name that matches the argument (which is OwnerBillClone)
  3. If the function returns false (or nil, which is a falsy result) – in other words, the function could not find any children named OwnerBillClone – then run the code inside this if statement.

The only problem with this code is assuming that your billboard GUI is literally named OwnerBillClone, so you might have to do some light editing to make his script work.

2 Likes