How to access BoolValues Inside a player in a Table?

Hello, I just started scripting this month, and I made a hitbox to detect players and storing them in a table. And I wan’t to get a BoolValue inside the player in the table, and checks if its true or false. My problem is I don’t know how to get the BoolValue, do I have to make another loop like the damagePlayer function in the serverscript? I don’t want to make a loop script everytime I wan’t to check a new BoolValue I might add.

I tried to remove the Target table in Hitbox Script and made it to return the Target.Parent directly, it works. And I can check it easily by just using FindFirstChild:, but it only detects 1 player at a time, I can’t hit multiple players. So I have to store the players inside the table or is there any other way?

Sorry if my explanation is bad, Its hard to explain everything in English. Here’s the script of what im trying to do.

Hitbox -

function CombatModule.hb(size, cframe, ignore)

	local hb = Instance.new("Part", workspace.Fx)
	hb.Name = "hb"
	hb.CFrame = cframe
	hb.Size = size
	hb.Anchored = true
	hb.CanCollide = false
	hb.CanQuery = false
	hb.Transparency = .5
	hb.Material = Enum.Material.ForceField
	hb.Color = Color3.new(1, 0, 0)

	local connect
	connect = hb.Touched:Connect(function()
		connect:Disconnect()   	
	end)

	local Targets = {}

	for i,v in pairs (hb:GetTouchingParts()) do

		if v.Parent:FindFirstChild("Humanoid") and table.find(ignore, v.Parent) == nil then

			local player = v.Parent

			if not Targets[player] then

				Targets[player] = true
				table.insert(Targets, player)	
			end				
		end	
	end

	hb:Destroy()
	if #Targets > 0 then return Targets
	else return nil		
	end
end

LocalScript -

uis.InputBegan:Connect(function(input, gpe)
	if gpe then return end
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		
		local hitTarg = combatModule.hb(Vector3.new(5,6,4), hrp.CFrame*CFrame.new(0,0,-3), {char}, hrp)
		
		if hitTarg then
			
			local data = {["Target"] = hitTarg, ["M1"] = "M1"}
			
			remote:FireServer(data)
			
		end	
	end
end)

ServerScript -

remote.OnServerEvent:Connect(function(player, data)
	
	local function damagePlayer(damage)
		
		for i,v in ipairs(data.Target) do

			if v:IsA("Model") then
				v:FindFirstChild("Humanoid"):TakeDamage(damage)
			end
		end
	end
	
	local ragdoll = data.Target:FindFirstChild("RagdollTrigger") -- its giving me error that I can't FindFirstChild in the table. do I have to make another loop like the function above?
	
	
	if ragdoll.Value == false and data.M1 == "M1" then
		
		damagePlayer(5)
		
	end		
end)
1 Like

Just one question, is there any reason you’re not opt’ing to just fire the event in the hitbox script, so you dont have to loop through all the targets?

for i,v in pairs (hb:GetTouchingParts()) do

		if v.Parent:FindFirstChild("Humanoid") and table.find(ignore, v.Parent) == nil then

			local player = v.Parent

			if not Targets[player] then

				Targets[player] = true --  ex. {Player1 = true, Player2 = true)
                remote:FireServer(v.Parent -- the character being hit)
				table.insert(Targets, player) -- Also this is not needed since you're already doing that above ^^
			end				
		end	
	end
3 Likes

Sorry for the late reply; I just got home from school. It works, and I never thought of this—thank you so much! However, I have a small problem; I want to send another parameter to the FireServer() function, by calling the function in the local script. I want to send another data.

I have a solution in mind, but I’m not sure if it’s efficient. My plan is to add a new parameter in hb(data) . It works, but I want to know if there’s a more efficient way, because I might call this function again and send different data from another local script."

I hope you understand what I’m saying, my grammar might be incorrect, and I’m very sorry. I’m very tired and finding it hard to think because I just got home from school.

My Solution

for i,v in pairs (hb:GetTouchingParts()) do

		if v.Parent:FindFirstChild("Humanoid") and table.find(ignore, v.Parent) == nil then

			local player = v.Parent

			if not Targets[player] then

				Targets[player] = true
                remote:FireServer(v.Parent, data)
			end				
		end	
	end			

---LocalScript
local data = {		
		   ["Downslam"] = Downslam,	
		   ["Uptilt"] = Uptilt,
 		   ["M1"] = M1
        }
        
		local hitTarg = combatModule.hb(Vector3.new(5,6,4), hrp.CFrame*CFrame.new(0,0,-3), {char}, remote, data)
1 Like

Honestly, you can just send all the data through a table, since the speed of individual arguments vs. a table of arguments have a very slight speed difference but nothing that you should need to worry about.

Also your tables as of now seem to be using strings to name the values, ex. [“Downslam”] but it’d honestly be better to just have it as ex. TheDownslam = Downslam – you can change the name

Since first it looks a little bit better, faster to type, and easier to get from the table

local args = {
TheDownslam = Downslam
}
args.TheDownslam -- This is how'd you could retrieve it
args["TheDownslam"] -- You can also retrieve it this way

So, to answer your question I would put all your arguments into a table not just the M1,uptilt, or downslam. Then I’d send it through so you’d only have one table to retrieve and send you have to send and it looks much cleaner.

ex.

Hitbox.Size = Data.Size
2 Likes

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