Combat System Problem

Local Script:

local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local player = game.Players.LocalPlayer

local uis = game:GetService("UserInputService")
local ts = game:GetService("TweenService")

local remote = game:GetService("ReplicatedStorage").Combat
local remoteRock = game:GetService("ReplicatedStorage"):WaitForChild("Rock")

local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Whitelist
params.FilterDescendantsInstances = {workspace.Map}

local lastTimeM1 = 0
local lastM1End = 0
local combo = 1

local canAir = true

local punchAnims = {
	'rbxassetid://13111415464', -- 1
	'rbxassetid://13111417311', -- 2
	'rbxassetid://13111419879', -- 3
	'rbxassetid://13111422893', -- 4
	'rbxassetid://13111431501', -- 5
}


local airAnims = {
	'rbxassetid://13103638685', -- KICK UP
	'rbxassetid://13103652945', -- KICK DOWN
}

local function hb(size, Cframe, ignore, char)
	local hb = Instance.new("Part", workspace.Fx)
	hb.Anchored = true
	hb.CanCollide = false
	hb.Transparency = 0.6
	hb.Name = "hb"
	hb.Material = Enum.Material.ForceField
	hb.CanQuery = false
	hb.Size = size
	hb.CFrame = Cframe
	
	local con 
	con = hb.Touched:Connect(function()
		con:Disconnect()
	end)
	
	local lasttarg
	
	for i, v in pairs(hb:GetTouchingParts()) do
		if v.Parent:FindFirstChild("Humanoid") and table.find(ignore, v.Parent) == nil then
			if lasttarg then
				if (lasttarg.Position - char.PrimaryPart.Position).Magnitude > (v.Position - char.PrimaryPart.Position).Magnitude then
					lasttarg = v.Parent.PrimaryPart
				end
			else
				lasttarg = v.Parent.PrimaryPart
			end
		end
	end
	
	hb:Destroy()
	if lasttarg then
		return lasttarg.Parent
	else
		return nil
	end
end

local function rock(data)
	print("TEEEEEST") -- IT'S NOT WORKING
	local currentTime = tick()
	local rockRaycastResult
	repeat
		rockRaycastResult = workspace:Raycast(data.Target.PrimaryPart.Position, data.Direction, params)
		print(rockRaycastResult)
		wait()
	until tick() - currentTime > 5 or rockRaycastResult ~= nil
	
	if rockRaycastResult then
		for i = 0, 14 do
			local part = Instance.new("Part", workspace.Fx)
			part.Size = Vector3.new(4, math.random(10, 20) / 10, math.random(10, 20) / 10)
			part.Anchored = true
			part.CFrame = CFrame.new(rockRaycastResult.Position, rockRaycastResult.Position + rockRaycastResult.Normal)
			part.CFrame = part.CFrame + CFrame.Angles(math.rad(90), math.rad(i * 360/14), 0) * CFrame.new(0, 0, -4 * 2) * CFrame.Angles(math.rad(35), 0, 0)
			part.CanQuery = false
			part.CanCollide = false
			part.CanTouch = false
			
			local result = workspace:Raycast(part.Position + rockRaycastResult.Normal * 4, rockRaycastResult.Normal * -5, params)
			if result then
				part.Position = result.Position
				part.Material = result.Material
				part.Color = result.Instance.Color
			else
				part:Destroy()
			end
			
			part.Position = part.Position + rockRaycastResult.Normal * -4
			ts:Create(part, TweenInfo.new(.2, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out, 0, false, 0), {Position = part.Position + rockRaycastResult.Normal * 4}):Play()
			
			spawn(function()
				game.Debris:AddItem(part, 4)
				wait(3)
				ts:Create(part, TweenInfo.new(.5, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out, 0, false, 0), {Position = part.Position + rockRaycastResult.Normal * -4}):Play()
			end)
			
			if i % 3 < 2 and result then
				local rubble = part:Clone()
				rubble.Size = Vector3.new(math.random(10, 20) / 20, math.random(10, 20) / 20, math.random(10, 20) / 20)
				rubble.Position = result.Position + rockRaycastResult.Normal * 4
				rubble.Material = result.Material
				rubble.Color = result.Instance.Color
				
				rubble.Parent = workspace.Fx
				rubble.Anchored = false
				rubble.CanCollide = true
				
				local bv = Instance.new("BodyVelocity", rubble)
				bv.Velocity = Vector3.new(math.random(-40, 40), 30, math.random(-40, 40))
				bv.MaxForce = Vector3.new(99999, 99999, 99999)
				bv.Name = "Velocity"
				
				game.Debris:AddItem(bv, .1)
				game.Debris:AddItem(rubble, 4)
				
				spawn(function()
					wait(2)
					
					ts:Create(rubble, TweenInfo.new(1, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out, 0, false, 0), {Transparency = 1}):Play()
				end)
				
				rubble.Transparency = 0
			end
		end
	end
end

uis.InputBegan:Connect(function(input, gpe)
	if gpe then return end
	
	if input.UserInputType == Enum.UserInputType.MouseButton1 and tick() - lastTimeM1 > .3 and tick() - lastM1End > .7 then
		if tick() - lastTimeM1 > .7 then
			combo = 1
		end
		
		lastTimeM1 = tick()
		
		local animation = Instance.new("Animation", workspace.Fx)
		local air = nil
		
		if uis:IsKeyDown("Space") and combo == 3 and canAir then
			canAir = false
			animation.AnimationId = airAnims[1]
			air = "Up"
		elseif not uis:IsKeyDown("Space") and combo == 4 or 5 and not canAir then
			animation.AnimationId = airAnims[2]
			air = "Down"
		else
			animation.AnimationId = punchAnims[combo]
		end
		
		local load = humanoid:LoadAnimation(animation)
		load:Play()
		
		animation:Destroy()
		
		local hitTarg = hb(Vector3.new(4, 6, 4), character.PrimaryPart.CFrame * CFrame.new(0, 0, -3), {character} ,character)
		
		if hitTarg then
			local data = {
				["Target"] = hitTarg,
				["Character"] = character,
				["Combo"] = combo,
				["Air"] = air,
				["Action"] = "ml",
			}
			
			remote:FireServer(data)
		end
		
		if combo == #punchAnims then
			combo = 1
			lastM1End = tick()
		else
			combo += 1
		end
		
		humanoid.WalkSpeed = 0
		wait(.4)
		humanoid.WalkSpeed = 13
	end
end)

print("TEST") -- IT'S WORKING

remoteRock.OnClientEvent:Connect(function(data) -- IT ISN'T WORKING
	print("CLIENT")
	if data.Action == "Rock" then 
		print("CLIENT 2")
		rock(data)
	end
end)

humanoid.StateChanged:Connect(function(old, new)
	if new == Enum.HumanoidStateType.Landed then
		canAir = true
	end
end)

uis.JumpRequest:Connect(function()
	if tick() - lastTimeM1 < 1 then
		humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
	else
		humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)
	end
end)

Script:

local remote = game:GetService("ReplicatedStorage"):WaitForChild("Combat")
local remoteRock = game:GetService("ReplicatedStorage"):WaitForChild("Rock")

remote.OnServerEvent:Connect(function(client, data)
	if data.Action == "ml" then
		data.Target.Humanoid:TakeDamage(5)
		if data.Air == "Up" then
			local bp = Instance.new("BodyPosition")
			bp.Position = data.Character.PrimaryPart.Position + Vector3.new(0, 30, 0)
			bp.P = 1200
			bp.MaxForce = Vector3.new(99999, 99999, 99999)
			bp.D = 200
			bp.Name = "Position"
			bp.Parent = data.Character.PrimaryPart
			game.Debris:AddItem(bp, 1)
			
			local bp = Instance.new("BodyPosition")
			bp.Position = data.Target.PrimaryPart.Position + Vector3.new(0, 30, 2)
			bp.P = 1200
			bp.MaxForce = Vector3.new(99999, 99999, 99999)
			bp.D = 200
			bp.Name = "Position"
			bp.Parent = data.Target.PrimaryPart
			game.Debris:AddItem(bp, 1)
						
		elseif data.Air == "Down" then
			for i, v in	 pairs(data.Target.PrimaryPart:GetChildren()) do
				if v:IsA("BodyMover") then
					v:Destroy()
				end
			end
						
			local bv = Instance.new("BodyVelocity", data.Target.PrimaryPart)
			bv.Velocity = (data.Character.PrimaryPart.CFrame.LookVector * 1 - Vector3.new(0, 2, 0)) * 25
			bv.MaxForce = Vector3.new(99999, 99999, 99999)
			bv.Name = "Velocity"
			game.Debris:AddItem(bv, .2)
			
			data.Action = "Rock" -- IT ISN'T WORKING
			data.Direction = (data.Character.PrimaryPart.CFrame.LookVector * 1 - Vector3.new(0, 2, 0)) * 1 -- IT ISN'T WORKING
			remote:FireAllClients(data) -- IT ISN'T WORKING
			
						
		elseif data.Combo == 5 then
			
						
			for i, v in pairs(data.Target.PrimaryPart:GetChildren()) do
				if v:IsA("BodyMover") then
					print("SOMETHING")
					v:Destroy()
				end
			end
			
			local bv = Instance.new("BodyVelocity", data.Character.PrimaryPart)
			bv.Velocity = data.Character.PrimaryPart.CFrame.LookVector * 10
			bv.MaxForce = Vector3.new(99999, 99999, 99999)
			bv.Name = "Velocity"
			game.Debris:AddItem(bv, .2)
			
			local bv = Instance.new("BodyVelocity", data.Target.PrimaryPart)
			bv.Velocity = data.Character.PrimaryPart.CFrame.LookVector * 75
			bv.MaxForce = Vector3.new(99999, 99999, 99999)
			bv.Name = "Velocity"
			game.Debris:AddItem(bv, .2)
		else
			local bv = Instance.new("BodyVelocity", data.Character.PrimaryPart)
			bv.Velocity = data.Character.PrimaryPart.CFrame.LookVector * 10
			bv.MaxForce = Vector3.new(99999, 99999, 99999)
			bv.Name = "Velocity"
			game.Debris:AddItem(bv, .2)

			local bv = Instance.new("BodyVelocity", data.Target.PrimaryPart)
			bv.Velocity = data.Character.PrimaryPart.CFrame.LookVector * 10
			bv.MaxForce = Vector3.new(99999, 99999, 99999)
			bv.Name = "Velocity"
			game.Debris:AddItem(bv, .2)
		end
	end
end)

So as you can see I have signed in the script what works and what does not. In short, the player with the enemy throws in the air, but when you land the enemy stones do not appear.

As I understand the problem is that I can not call the function that spawns stones. But the question is why I can’t? Because the enemy lands but nothing happens)

If anything, I wrote this script by guide here it is: Roblox Advanced Combat Tutorial Part 2 - YouTube

Also, here is my explorer:

There’s a man everything works)
Hope to hear back)

1 Like

why are they bullying you?
Did they give a reason??

You can forget about it.КKa As for me now it is better to deal with the problem in the script and already with the post I will deal with myself

And can you please help me with my problem that the function is not called?

Sure.

First off, have you programmed the raycast hitbox?.
If you have here is what to do:
Fire the function on Hitbox.Hit

If that isn’t working then just fire the rock function by itself, and see if it works.

Okay, look, I just removed the remote Event in the script, and just called the function in the local script, and as a result the print in the function worked. But if you look at the script, you will see at the end of the local script, that this function is called in the event that is triggered in the script. And this just does not work. Does this mean that the problem is that my event is not triggered?

I think that is the case or at least it looks like that.

Okay, then how do I fix this problem?

Found thy solution.

It looks like you are having a problem with invoking things.
Read through this and see if any of these apply to you:

And in your opinion, am I doing it right? I’m summoning a gem event here:

			data.Action = "Rock" 
			data.Direction = (data.Character.PrimaryPart.CFrame.LookVector * 1 - Vector3.new(0, 2, 0)) * 1 
			remote:FireAllClients(data) 

And I forgot here’s another local script where I create everything:

remote.OnClientEvent:Connect(function(data) -- IT ISN'T WORKING
	print("CLIENT")
	if data.Action == "Rock" then 
		print("CLIENT 2")
		rock(data)
	end
end)

Hold up.

Is your remote event even being activated on the client ?