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)