Im relatively new to Lua and roblox studio overall, and i came across this problem while trying to code an m1 system for my game. So far i have a script that spawns a hitbox every time the player punches but Im not sure on how to make it to where the hitbox makes other humanoids make Stunned = true. My hitbox code is included, thanks in advance for any advice.
"lua
local Workspace = game.Workspace
local Runservice = game:GetService("RunService")
local Hitbox = script.Parent
local AlreadyHit = {}
local PlayerHumanoid = game.Players.LocalPlayer.Character:FindFirstChild("Humanoid")
Runservice.Heartbeat:Connect(function()
local PartsDetected = Workspace:GetPartsInPart(Hitbox)
if PartsDetected then
for i, v in PartsDetected do
local Humanoid = v.Parent:FindFirstChild("Humanoid")
if Humanoid then
if not table.find(AlreadyHit, Humanoid) and Humanoid ~= PlayerHumanoid then -- checks if player is already hit
Humanoid:TakeDamage(10)
table.insert(AlreadyHit, Humanoid)
if Humanoid.Stunned == false then
Humanoid.Stunned = 1
wait(0.5)
Humanoid.Stunned = 0
end
end
end
end
end
end)
"
** You are now Level 2! **