Is there something wrong with my debouncing?

UIS.InputBegan:Connect(function(Input,IsTyping)
	if IsTyping then
		return
	elseif Input.UserInputType == Enum.UserInputType.MouseButton1 then
		      if Thrown == false then
			Thrown = true
			ThrowEvent:FireServer(Mouse.Hit,"Throw")
		end
	elseif Input.UserInputType == Enum.UserInputType.MouseButton2 then
	                if Thrown == true then
			Thrown = false
			wait(5)
			ThrowEvent:FireServer(Mouse.Hit,"Retrieve")
			
		end
	end
end)

The retrieve state of my throwevent of my script is not firing, so i figured it’s probably due to my debounces. But on the off chance that my problem lies elsewhere.
Here’s the part of the server script where it picks up on the event(Excerpt):

Throw.OnServerEvent:Connect(function(Player,Direction,State)
elseif State == "Retrieve" then
print("Retrieve in motion")
end	
end)

The print statement doesn’t run, How do I fix it?

you are not setting the debounce false again try this:

UIS.InputBegan:Connect(function(Input,IsTyping)
	if IsTyping then
		return
	elseif Input.UserInputType == Enum.UserInputType.MouseButton1 then
		      if Thrown == false then
			Thrown = true
			ThrowEvent:FireServer(Mouse.Hit,"Throw")
           wait(1) --how much sec u want
          Thrown = false
		end
	elseif Input.UserInputType == Enum.UserInputType.MouseButton2 then
	                if Thrown == true then
			Thrown = false
			wait(5)
			ThrowEvent:FireServer(Mouse.Hit,"Retrieve")
			 Thrown = true ---here
		end
	end
end)

Is Thrown defined before? Extra characters

Yup, it’s defined as false before.

1 Like

Tried the solution, the print statement still doesn’t run.

1 Like

its strange you are using elseif why not using if itself like:

 if State == "Retrieve" then
print("Retrieve in motion")
end
1 Like

The only thing I could see being wrong is that it’ll only work when you have thrown it already, did you try it out after throwing? If so, there may need to be some debugging to see what’s going on with the value of Thrown, try this code out so we can see what’s going on

UIS.InputBegan:Connect(function(Input,IsTyping)
	if IsTyping then return end
	
	print(Thrown)
	
	if Input.UserInputType == Enum.UserInputType.MouseButton1 then
		if not Thrown then
			Thrown = true
			ThrowEvent:FireServer(Mouse.Hit,"Throw")
		end
	elseif Input.UserInputType == Enum.UserInputType.MouseButton2 then
	    if Thrown then
			Thrown = false
			wait(5)
            print("Sending receive to ThrowEvent")
			ThrowEvent:FireServer(Mouse.Hit,"Retrieve")
		end
	end
end)

If it prints “Sending receive to ThrowEvent” then something is wrong with the remoteEvent

1 Like

It’s an excerpt the if statement is assumed to be defined before

1 Like

The elseif is a second condition, the first if is accomodating the “throw” state. Like I said, the script is an excerpt.

1 Like

Just to endorse this response, use print statements before calling to server to verify where your script is going when called. It’ll help with debugging

1 Like

Tried it, it’s not running the print statement. Also did you mean if it doesn’t print, then something is wrong?

1 Like

Are you left-clicking, and then right-clicking? Just to make sure

Which one? The one in the if statement or the value of Thrown? What value did Thrown have when testing? Are you remembering to throw it and then retrieve?

1 Like

Neither of them are running, the “Sending receive to throwevent” and “retrieve in motion”

of course, I am making thor’s hammer in which you have to throw before you can retrieve it. The throw part works btw, it’s the retrieval that’s the issue.

Was print(Thrown) working? When you were testing it out, was it still printing false when right clicking?

Just to summarize your pre-checks in case something might be wrong.

[ ] Is the UIS function in a localscript?

[ ] Is the serverEvent on a server script?

[ ] is the UIS function firing to the same exact Remote Instance as the OnServerEvent is connected to?

[ ] Are the scripts actually running? (verify by running a print statement “Running!” at the beginning of script)

It prints false regardless of the mouse button i was clicking.

Huh? Okay it should’ve atleast set it to true when left clicking, where are you setting up Thrown?

Yes, yes, yes, and yes. All yes

This is how it looks atm:

UIS.InputBegan:Connect(function(Input,IsTyping)
	if IsTyping then return end
	
	print(Thrown)
		
	if Input.UserInputType == Enum.UserInputType.MouseButton1 then
		-- Mjolnir Throw
		if Thrown == false then
			Thrown = true
			ThrowEvent:FireServer(Mouse.Hit,"Throw")
			Thrown = false
		end
	elseif Input.UserInputType == Enum.UserInputType.MouseButton2 then
		-- Mjolnir Return
		if Thrown == true then
			Thrown = false
			wait(5)
			print("Sending receive to ThrowEvent")
			ThrowEvent:FireServer(Mouse.Hit,"Retrieve")
		
			
		end
	end
end)