Touched event isn't a valid member of backpack

At the current moment I want to do a double check like I was recommended for my previous post. Although I need a Medium where I can used a Touched Event for the client to figure out what it is hitting at the moment, then decide on the server if that is what is trying to be hit and do the damage.


local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local HRP = Character:WaitForChild("HumanoidRootPart")
local Mouse = Player:GetMouse()

--\\ Debouncing Variables //--
local Enabled = true
local Count = 1

--\\ Services //--
local UIS = game:GetService("UserInputService")

--\\ Combat Activation //--
local S = script
local RE = S:WaitForChild("Combat")
----------------------------------------

--\\ Functions //--

UIS.InputBegan:Connect(function(Input, Processed)
	if Processed then
		return
	end
	if Input.UserInputType == Enum.UserInputType.MouseButton1 then
		if Enabled then
			local CFrames = HRP.CFrame * CFrame.new(0, 0, -2)
			script.Parent.Touched:Connect(function(hit, blacklist) --Issue comes here wher eI want to get the script to work.
				blacklist = {game.Part, game.Part:FindFirstChild("ParticleEmitter"), game.ReplicatedStorage.Hitbox, game.ReplicatedStorage.Cloudy, game.ReplicatedStorage["Charge up Partcile"], game.ReplicatedStorage.Events}
				--Blacklisting things I don't want to be counted as a damagable item/basepart. ^^^
				if Character.Hit == blacklist then return end
				if Count == 1 and Character.Hit ~= blacklist then
					
					Count = 2
					local Anim = Instance.new("Animation")
					Anim.AnimationId = "rbxassetid://7246225588"
					local AnimP = Character.Humanoid:LoadAnimation(Anim)
					AnimP:AdjustSpeed(3)
					AnimP:Play()
					
				elseif Count == 2 then
					Count = 3
					local Anim = Instance.new("Animation")
					Anim.AnimationId = "rbxassetid://7246227343"
					local AnimP = Character.Humanoid:LoadAnimation(Anim)
					AnimP:AdjustSpeed(3)
					AnimP:Play()
				elseif Count == 3 then
					Count = 4
					local Anim = Instance.new("Animation")
					Anim.AnimationId = "rbxassetid://7246232053"
					local AnimP = Character.Humanoid:LoadAnimation(Anim)
					AnimP:AdjustSpeed(3)
					AnimP:Play()
				elseif Count == 4 then
					Count = 1
					local Anim = Instance.new("Animation")
					Anim.AnimationId = "rbxassetid://7246223838"
					local AnimP = Character.Humanoid:LoadAnimation(Anim)
					AnimP:AdjustSpeed(3)
					AnimP:Play()
				end
				RE:FireServer("Combat", CFrames, hit)
			end)
			
		end
	end
end)

The error is this at the moment.
image

1 Like

Some issues with your code:

  1. The error happens because script.Parent is the backpack and the backpack does not support a Touched connection.
  2. if Character.Hit == blacklist then return end You can’t compare hit with a table like that, you will have to iterate through the table and compare each object with hit individually.
  3. Your Enabled debounce isn’t being used correctly, as you never set it to false.
  4. You are attempting to create a connection inside a connection, which isn’t good as that could in theory end up creating multiple connections if not handled properly.
  5. You dont need to store the script in a variable like you did with local S = script

Also instead of creating the Touched connection client sided and validating it on the server, you could simply just create it server sided and then you will always know it’s legit.

2 Likes
  1. So, what could instead since the Backpack will not work. The general way someone was showing me was through a Touched Event, but I won’t be able to do that if I can’t even run the Touched Event

  2. So I’d have to run an i,v for pairs for everything in the table? Per Animation? To check for what was hit then verify and deny anything in the blacklist?

  3. Oh, I was never good with debounces. I’ll look more into them but my understanding of them is very low.

  4. Is there an alternative/better way or method of doing this that I can learn? I have done this method many times, but it often worked out with little to no issues.

  5. I just like it better. Personal preference I would say.

The server is already handling creating the hitbox, but the issue with that was related to a latency issue so that’s why I’m trying to do the touched event method and get it verified again in the server. It looks like this at the moment, and I want to fix it.

https://i.gyazo.com/4b9c8f043d51b4491597fa76d932a884.mp4

(Along with a better way to do debounce but I could look around the DevForum and learn that myself.)

2 Likes
  1. Touched connections can only be used on physical objects like parts, unions, and meshes. I do not know what you are wanting to be touched to fire the connection. But because you put it inside an InputBegan connection, the touch connection will never exist unless the input was made. And every time you make a new input, it creates another connection, and another, and another… see my point?

  2. Yea you would have to iterate through the blacklist table and and check if whatever hit is, matches what is in the table. Also note: Character.Hit does not exist, as Hit is not a property of the Character. If you want to check if a limb was touched, you need to use .Touched on the limb. Also your blacklist contains objects that can not be touched, since only BaseParts can be touched.

  3. Debounces are fairly simple. They are mainly used to prevent code from being ran after a set amount of time. You simply check if its true or false, then set it to the opposite, wait some time, then set it back to how it was. That easy.

  4. Refer to what I mentioned in #1

  5. It’s using up an unnecessary variable space in the script and in the memory. Yes there is a limit to how many variables you can have in a script. Also as for performance, probably wouldn’t help either.

1 Like

So, at the current moment I’d have to find a different method? I just want the latency to get much easier to deal with. So, I don’t deal with lasting hitboxes/inaccurate hitboxes on the server.

1 Like

script.Parent should be a reference to the “Handle” of the tool instance itself, so start by moving the script into the Handle part.

The Combat I am using is click combat, it isn’t bound to a tool.

Are parts even involved? The Touched event is only fired when a BasePart instance is touched.

No, the parts I was trying to use were the arms on the character and get what they touched.

Where is the script parented to when it executes?

:arrow_forward: {…} - Server

Is what I see when I press.

Isn’t backpack a Gui?

Only when a tool is inside I believe.

Managed to make a better method of lag latency issues, make a simpler hitbox.