You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Fix the problem
-
What is the issue? so i use a raycast hitbox for my fighting game, i use a raycast module that fires a remote function to indicate somethings been hit but when someone elses raycast hits something, another players connect function thing fires aswell
-
What solutions have you tried so far? i have tried disconnecting the function after a set amount of time etc. 0.4 seconds and it hasnt worked
this is my code
local module2 = {}
params = OverlapParams.new()
local module = require(game.ReplicatedStorage.RayCast)
local module3 = require(game.ReplicatedStorage.Stun)
counter = script.count
function module2.attack()
local cd = script.cd
if cd.Value == false then
cd.Value = true
player = player
if counter.Value == 1 then
counter.Value = 2
local anim1 = script.Parent.Parent.Humanoid:LoadAnimation(script.Punch1)
anim1:Play()
elseif counter.Value == 2 then
counter.Value = 3
local anim2 = script.Parent.Parent.Humanoid:LoadAnimation(script.Punch2)
anim2:Play()
elseif counter.Value == 3 then
counter.Value = 1
local anim3 = script.Parent.Parent.Humanoid:LoadAnimation(script.Punch3)
anim3:Play()
end
script.Parent.Punching.Value = true
task.spawn(function()
local s,f = pcall(function()
if not script.Parent.Parent then
connect:Disconnect()
end
end)
if f then
connect:Disconnect()
end
for i = 1,2 do
local rayDirection = script.Parent.Parent.HumanoidRootPart.CFrame.LookVector.Unit * 5
local rayOrigin = script.Parent.Parent.Torso.Position
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {workspace.Map,script.Parent.Parent,workspace.Lobby,workspace.Spawns, workspace.lobbypart}
raycastParams.FilterType = Enum.RaycastFilterType.Exclude
raycastParams.IgnoreWater = false
raycastParams.RespectCanCollide = true
module:Raycast(rayOrigin,rayDirection,raycastParams)
task.wait(0.1)
end
end)
wait(0.4)
script.Parent.Punching.Value = false
task.wait(script.Parent.Parent.Speed.Value)
cd.Value = false
end
end
connect = module.RaySuccess:Connect(function(hit)
if script.Parent.Punching.Value == true then
if hit then
local hum = hit.Parent:FindFirstChild("Humanoid")
if hum then
if hum.Health >= 1 then
if game.Players:FindFirstChild(hit.Parent.Name) then
if hit.Parent.Name ~= script.Parent.Name then
if hit.Parent.IsRagdolled.Value == false then
if hit.Parent.InArena.Value == true then
if script.Parent.Parent.IsRagdolled.Value == false and hit.Name ~= "Hitbox" then
local s,f = pcall(function()
if hit.Parent:GetAttribute("Block") == true then
script.Parent.Punching.Value = false
local hiteffect = game.ReplicatedStorage.hit.Attachment:Clone()
hiteffect.Parent = hit.Parent["Right Arm"]
game.Debris:AddItem(hiteffect,3)
hiteffect[" effect"]:Emit(15)
hiteffect[" effect2"]:Emit(15)
wait()
hiteffect[" effect3"]:Emit(15)
hiteffect["effect 4"]:Emit(15)
hit.Parent.Blockbar.Value -= 35
hit.Parent.LastHit.Value = script.Parent.Name
return
end
if hit.Parent:GetAttribute("Counter") == true then
hit.Parent.LastHit.Value = script.Parent.Name
hit.Parent.IsRagdolled.Value = true
return
end
local sound = script.punch:Clone()
script.Parent.Punching.Value = false
sound.Parent = hit
sound:Play()
local player = game.Players:GetPlayerFromCharacter(script.Parent.Parent)
local hiteffect = game.ReplicatedStorage.hit.Attachment:Clone()
if script.count.Value == 2 then
hiteffect.Parent = script.Parent.Parent["Right Arm"]
elseif script.count.Value == 3 then
hiteffect.Parent = script.Parent.Parent["Left Arm"]
elseif script.count.Value == 1 then
hiteffect.Parent = script.Parent.Parent["Right Arm"]
end
hiteffect[" effect"]:Emit(15)
hiteffect[" effect2"]:Emit(15)
wait()
hiteffect[" effect3"]:Emit(15)
hiteffect["effect 4"]:Emit(15)
hit.Parent.IsRagdolled.Value = true
--hit.Parent.RagdollTrigger.Value = true
hum:TakeDamage(7)
hit.Parent.LastHit.Value = script.Parent.Name
if script.count.Value == 2 or script.count.Value == 3 then
module3:Stun(hit.Parent,1)
elseif script.count.Value == 1 then
hit.Parent.RagdollTrigger.Value = true
local velocity = Instance.new("BodyVelocity",hit.Parent.HumanoidRootPart)
velocity.MaxForce = Vector3.new(3,3,3) * math.huge
local dir = (hit.Parent.HumanoidRootPart.CFrame.Position - script.Parent.Parent.HumanoidRootPart.Position).Unit
velocity.Velocity = (dir + Vector3.new(0,100,0)).Unit * script.Parent.Parent.Power.Value
local rot = Instance.new("BodyAngularVelocity",hit.Parent.HumanoidRootPart)
rot.AngularVelocity = Vector3.new(0.3,0.5,0.3) * math.pi *5
rot.MaxTorque = Vector3.new(2,50,2) *math.huge
rot.P = 10000
game:GetService("Debris"):AddItem(velocity, 0.2)
game:GetService("Debris"):AddItem(rot,0.2)
end
task.wait(0.3)
hit.Parent.IsRagdolled.Value = false
hit.Parent.RagdollTrigger.Value = false
wait(0.3)
sound:Destroy()
end)
if f then
warn(f)
script.Parent.Parent.IsRagdolled.Value = false
script.Parent.Parent.RagdollTrigger.Value = false
script.Parent.Parent.Humanoid.AutoRotate = true
script.Parent.Parent.Humanoid.WalkSpeed = 16
end
end
end
end
end
end
end
end
end
end
end)
script.Parent.Parent.Humanoid:GetPropertyChangedSignal("Health"):Connect(function()
if script.Parent.Parent.Humanoid.Health <= 1 then
connect:Disconnect()
end
end)
return module2
any help would be appreciated