Touched event only working once

Hey All

Basically trying to change some stuff about a part when it’s touched, which does work well the first time, but if a player goes to touched the part again, none of the script executes. I do have debounce’s in place (when part is touched, makes it so it can’t touch again, but if they player presses Q you can touch the part again), but they don’t seem to be working. I have the debounce as a boolean, and the boolean as a BoolValue. Pressing Q does set the debounce to false so the player can touch it again, but when the player touches the part, nothing happens.

Script 1:

local partThing = game.Workspace.pickupPart --Gets the part

--Debounce's
local debounce = Instance.new("BoolValue", partThing)
debounce.Name = "debounce"
debounce.Value = false


partThing.Part.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild('Humanoid') and debounce.Value == false then
		
--The code is here but for readability's sake I've removed unnecessary code

		--Checkpoint 1
		print("Touched " .. partThing.Name) --Letting me know the code worked
		
		game.Workspace.pickupPart.debounce.Value = true
	end
end)

Script 2:

UIS.InputBegan:Connect(function(input, gameProccesedEvent)
	if input.KeyCode == Enum.KeyCode.Q then
		game.Workspace.pickupPart.debounce.Value = false
		print("Dropped")

        --Yet again more stuff in here
		
		if game.Workspace.pickupPart.debounce.Value == false then
			print("debounce false")
		end
	end
end)

Any help would be greatly appreciated, thanks!

You’re never setting Debounce.Value to false and you’re telling your code to work when Debounce.Value is false if that makes sense.

1 Like

Can you show your script that handles the debounce reset? Since it is important for this as it could be the reason for the issue.

1 Like

Oops! forgot to add that. Thanks for reminding me!

1 Like

Added the script in. Thanks for reminding me!

I added the script into the post, hope you can help!

so you’re setting Denounce.Value to false on a local script which means server won’t see it. That means server will still see Debounce.Value as true

2 Likes

Ohhhhh. How would I be able tochange the value without converting it to a script?

You can use a remote event to change value if you wish.

Not to good at using remote events, would you possibly be able to give a short tutorial?

yeah you can just do these:

--in a server script
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player, goal)
   game.Workspace.pickupPart.debounce.Value = goal
end)

and on your UserInputService script remove game.Workspace.pickupPart.debounce.Value = false line and add this one instead: game.ReplicatedStorage.RemoteEvent:FireServer(false)

1 Like

One other small issue if you don’t mind, is that when you touch the part again, the size of the part isn’t changing inside the script, could you possibly help with this?

Script:

		partThing.Size = Vector3.new(1.186, 0.949, 1.191)

Can i see a bit more about the script if possible?

1 Like

If you want the whole script, here you go!

local partThing = game.Workspace.pickupPart --Gets the part

--Debounce's
local debounce = Instance.new("BoolValue", partThing)
debounce.Name = "debounce"
debounce.Value = false


partThing.Part.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild('Humanoid') and debounce.Value == false then
		
		--Variables
		local gloveR = hit.Parent.GloveHandRight --Gets right hand
		local HRP = hit.Parent.GloveHandRight.HandRootPart --Root part of hand
		

		--Checkpoint 1
		print("Touched " .. partThing.Name) --Letting me know the code worked
		
		--Setting Basics
		partThing.CanCollide = false --Disabling CanCollied (let's you walk thorugh it)
		partThing.Anchored = false 
		
		--Creating weld
		local newWeld = Instance.new("WeldConstraint", partThing) --Creates new weld
		newWeld.Name = "pickupWeld"
		newWeld.Part0 = partThing --Sets cloned part as main part
		newWeld.Part1 = HRP --Welds part to HRP

		--Resizng & Position
		local MiddlePosition = (hit.Parent.GloveHandRight.Finger2.UpperFinger.Position + hit.Parent.GloveHandLeft.Finger2.UpperFinger.Position) / 2
		partThing.Position = MiddlePosition --Sets Position
		partThing.Size = Vector3.new(1.186, 0.949, 1.191)
		partThing.Orientation = HRP.Orientation
		
		--Changes transparency modifier to 0
		game.Workspace.pickupPart.LocalTransparencyModifier = 0
		
		--Resize and reposition hitbox
		game.Workspace.pickupPart.Part.Size = game.Workspace.pickupPart.Size
		game.Workspace.pickupPart.Part.Orientation = game.Workspace.pickupPart.Orientation
		game.Workspace.pickupPart.Part.Position = game.Workspace.pickupPart.Position
		
		game.Workspace.pickupPart.debounce.Value = true
	end
end)

So you’re saying it’s never changing the size? Because it looks fine to me. I don’t know if you’re changing the size on somewhere else again.

It changes the size when it’s touched for the first time, but if it’s touched again it doesn’t change size

Because it is still in the same size. You’re never changing the Size after that.

Here’s what happens

Are you changing the size again inside UserInputService code? if so you need to use remote events again i mean you can just add that to the current remoteevent code.