-
What do you want to achieve? Keep it simple and clear!
I wanted to make when you hit someone it played the effects he would take damage and get stunned -
What is the issue? Include screenshots / videos if possible!
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Rescripting the entire code
and using other features
local Remote = game.ReplicatedStorage:WaitForChild("Punch")
local StunHandler = require(game.ServerScriptService.StunHandlerV2)
local Debris = game:GetService("Debris")
IsBeingTouched = false
local Damage = math.random(11,12)
Remote.OnServerEvent:Connect(function(plr)
local Character = plr.Character or plr.CharacterAdded:Wait()
local HumanoidRoot = Character:WaitForChild("HumanoidRootPart")
local Humanoid = Character:WaitForChild("Humanoid")
local Part = game.ReplicatedStorage:WaitForChild("PunchHitBox"):Clone()
local Effect = game.ReplicatedStorage:WaitForChild("HitEffect"):Clone()
Part.Parent = workspace
Part.CFrame = HumanoidRoot.CFrame * CFrame.new(Vector3.new(0,0,-4))
Part.Touched:Connect(function(hit)
if hit.Parent == Character then return end
if hit.Parent:FindFirstChild("Humanoid") and not IsBeingTouched then
hit.Parent:WaitForChild("Humanoid"):TakeDamage(Damage)
hit.Parent.Stunned.Value = true
Effect.Parent = workspace
Effect.CFrame = hit.Parent:WaitForChild("UpperTorso").CFrame
StunHandler.Stun(hit.Parent:WaitForChild("Humanoid"),0.4)
wait(0.4)
Effect:Destroy()
hit.Parent.Stunned.Value = false
end
end)
wait(0.4)
Part:Destroy()
end)