#Not sure on how to code hitstun

1 messages · Page 1 of 1 (latest)

earnest fossil
#

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)
"

warped ore
#

humanoid.stunned isn't a real property, also you are doing this on the client which wont affect other people, combat should run on the server, use an attribute on the humanoid and toggle it server side

#

also using wait inside heartbeat only pauses the thread not the heartbeat loop, which means a new routine every frame ( which is a big no no )

#

also unless u meant for the stun to last forever and people to be un hittable after the stun ends, u will need a timer for that player specifically, to clear them after ur set stun time

#

look into everything i said in detail, im covering what should be extremely basic concepts for someone making a combat type game

hoary brambleBOT
#

studio** You are now Level 2! **studio

earnest fossil
#

also thanks for the advice

#

also the reason it only does it once is that the hitbox is just cloned and destroyed so the list wont tranfer to another new hitbox with a new list

#

here is some of my punch code to help show what i mean

#

local function Punch(PunchType)
if PunchType == 1 then
PunchAnim1Track:Play()
CreateHitbox()
PunchAnim1Track.Stopped:Wait()
DestroyHitbox()
elseif PunchType == 2 then
PunchAnim2Track:Play()
CreateHitbox()
PunchAnim2Track.Stopped:Wait()
DestroyHitbox()
elseif PunchType == 3 then
PunchAnim3Track:Play()
CreateHitbox()
PunchAnim3Track.Stopped:Wait()
DestroyHitbox()
elseif PunchType == 4 then
PunchAnim4Track:Play()
CreateHitbox()
PunchAnim4Track.Stopped:Wait()
DestroyHitbox()
end
end

warped ore
#

mb, i had to assume the worst since u were running it client sided

hoary brambleBOT
#

studio** You are now Level 1! **studio

earnest fossil
#

but im not sure how to run it NOT client sided

warped ore
#

???

earnest fossil
#

client sided just means using local scripts right>

#

?

warped ore
#

yes

#

its pretty easy to run it server sided

earnest fossil
#

oh i thought i would have to change my code

warped ore
#

u do

earnest fossil
#

oh

#

how do i know what to change?

warped ore
#

learn what is possible server sided and what is possible client sided

#

u cant manipulate teh environment of other players on client side

#

but you cant use run service and whatnot on server side

earnest fossil
warped ore
#

for now research what is possible clietn and server side especially for humanoids

earnest fossil
#

ok got it

#

once again thanks

warped ore
#

i would do it for u, but u will never learn

#

if u do get stuck il help u but atleast put effort

earnest fossil
hasty cedar
warped ore
#

got u 🙂

hasty cedar
#

hard to say they're making a combat type game, looks like just the mechanic

#

i give another couple of days before they give up

warped ore
hasty cedar
#

anyone cloning parts with a script in it to do hitboxes is in way over their head

warped ore
#

i lost my other acc and want to build some rep before i go for my ranks again

warped ore
hasty cedar
hasty cedar
warped ore
#

no diss to toast tho

hasty cedar
earnest fossil
#

bro im just asking a question no need to diss

#

also yes its a combat game

#

im just doing this for fun so im just sticking with this

#

aint trying to make a button clicker thats boring asl

warped ore
#

nah u got this, i reccomend actually watching tuts tho, since ur making numerous fundamental mistakes that people who only use ai to code dont even make

earnest fossil
#

oh ok

#

i personally didnt do tuts bc one of my coder friends said that i shouldnt do that

hasty cedar
#

that hitbox:clone() is going to cause you problems later

earnest fossil
#

and that i should just look at the docs

warped ore
#

i learned lua 5.1 directly from docs and i have got to say, a 4hr yt tut would make me alot more proficient but i do have nuanced knowledge in some parts

earnest fossil
hasty cedar
warped ore
#

instead go onto youtube and watch tuts on how people make hit boxes and stun effects

#

until u get teh gist

earnest fossil
#

kk

warped ore
earnest fossil
#

yeah i tried raycast and it was too complicated for me to understand

hasty cedar
#

indeed, copy the technique from a tutorial

warped ore
#

also ensure to claim credit for the code and change comments

hasty cedar
#

i said copy the technique not the code

warped ore
#

to make it seem like urs

earnest fossil
warped ore
#

many ppl do that to claim credit

hasty cedar
earnest fossil
#

ngl i dont think id really need to claim credit bc its just a snippet of code

hoary brambleBOT
#

studio** You are now Level 2! **studio

warped ore