Problem with Rock spawn

So let me start over, I created a tool “Combat”, and the player can easily hit them and kill nps, but the problem is that in my script player can toss the enemy in the air and when the enemy lands under him appear stones, the problem is that they do not appear, and the function itself is simply not called.

I tell you in advance that I did combat (not tool) according to the guide, here it is: Roblox Advanced Combat Tutorial Part 2 - YouTube
The timecode on which it shows the result: (before it he writes the script): 6:50

And here is where the script is located:
Снимок экрана 2023-04-24 в 20.05.20

Local Script:

local rp = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")
local starterPlayer = game:GetService("StarterPlayer")
local starterCharacter = starterPlayer:WaitForChild("StarterCharacterScripts")
local RunService = game:GetService("RunService")
local UIS = game:GetService("UserInputService")
local ts = game:GetService("TweenService")


local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local tool = script.Parent
local event = rp:WaitForChild("Combat")
local Animations = rp:WaitForChild("Animations")

local combatIdle = humanoid:LoadAnimation(Animations:WaitForChild("CombatIdle"))

local RealIdle = humanoid:LoadAnimation(character:WaitForChild("Animate"):WaitForChild("idle"):WaitForChild("Animation1"))

tool.RequiresHandle = false

local data = game.Players.LocalPlayer:WaitForChild("Data")
local inCombat = data.InCombat

inCombat.Value = false

local combo = 1
local canAir = true
local lastTimeM1 = 0
local lastM1End = 0

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


local basicAnims = {
	"rbxassetid://13111415464", -- COMBO 1
	"rbxassetid://13111417311", -- COMBO 2
	"rbxassetid://13111419879", -- COMBO 3
	"rbxassetid://13111422893", -- COMBO 4
	"rbxassetid://13111431501", -- COMBO 5
}

local airAnims = {
	"rbxassetid://13103638685", -- AIR UP
	"rbxassetid://13103652945", -- AIR DOWN
}

tool.Equipped:Connect(function()
	RealIdle:Stop()
	combatIdle:Play()
	inCombat.Value = true
end)

tool.Unequipped:Connect(function()
	combatIdle:Stop()
	RealIdle:Play()
	inCombat.Value = false
end)

local function IsPlayerMoving()
	if humanoid.MoveDirection.Magnitude >= 1 then
		RealIdle:Stop()
		combatIdle:Stop()
	end
end

RunService.RenderStepped:Connect(IsPlayerMoving)


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 crater(data)
	local currentTime = tick()
	local craterRaycastResult
	repeat
		craterRaycastResult = workspace:Raycast(data.Target.PrimaryPart.Position, data.Direction, params)
		print(craterRaycastResult)
		wait()
	until tick() - currentTime > 5 or craterRaycastResult ~= nil
	if craterRaycastResult 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(craterRaycastResult.Position, craterRaycastResult.Position + craterRaycastResult.Normal)
			part.CFrame = part.CFrame * CFrame.new(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 + craterRaycastResult.Normal * 4, craterRaycastResult.Normal * -5, params)
			print(result)
			if result then
				part.Position = result.Position
				part.Material = result.Material
				part.Color = result.Instance.Color
			else
				part:Destroy()
			end
			
			part.Position = part.Position + craterRaycastResult.Normal * -4
			ts:Create(part, TweenInfo.new(.2, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out, 0, false, 0), {Position = part.Position + craterRaycastResult.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 + craterRaycastResult.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 + craterRaycastResult.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 inCombat.Value == false 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 == 5 and not canAir then
			animation.AnimationId = airAnims[2]
			air = "Down"
		else
			animation.AnimationId = basicAnims[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",
			}
			
			event:FireServer(data)
		end
		
		if combo == #basicAnims then
			combo = 1
			lastM1End = tick()
		else
			combo += 1
		end
		
		humanoid.WalkSpeed = 0
		wait(0.4)
		humanoid.WalkSpeed = 13
	end
end)

event.OnClientEvent:Connect(function(data)
	if data.Action == "Crater" then
		crater(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 rp = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")
local starterPlayer = game:GetService("StarterPlayer")
local starterCharacter = starterPlayer:WaitForChild("StarterCharacterScripts")
local RunService = game:GetService("RunService")
local UIS = game:GetService("UserInputService")

local event = rp:WaitForChild("Combat")


event.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 = "Crater"
			data.Direction = (data.Character.PrimaryPart.CFrame.LookVector * 1 - Vector3.new(0, 2, 0)) * 4
			event:FireAllClients(data)
			
		elseif data.Combo == 5 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.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)
1 Like

Is it perhaps because the script is inside the tool? I know that certain types of script do not run unless in the correct place.

I think the CombatTool script is a local script (not familiar with the newer default icons. Been using Vanilla 3 icons the same day they updated). LocalScripts can run in tools, so I don’t think that’s it.

Can you tell me exactly which function isn’t running?

Ah, sorry for the confusing. The script I’m refering to is “CombatServer” which is in the tool. Localscripts have the computer in the bottom corner, and it looks to me like “CombatServer” is a server script

Server scripts can run in tools as well, so it is probably an issue in the code. Server scripts can run just about anywhere. The only place I know they can’t is in ReplicatedFirst

1 Like

The function called “crater” does not work

Yes, I also think that the problem is not in the layout of the script, since the other functions of the script, both local and normal, such as airCombo, and the usual duars are executed, but it is one function “crater”, is not performed

I think this is your problem. The event doesn’t get fired anywhere. If you didn’t finish following the whole video, you might’ve missed where this event fires the client on the server? Unless it is in a different server script, this is most likely why.

So the thing is that he wrote a script and then ran it and it all worked I looked at everything! So I don’t think I overlooked anything.

Can you show me any other scripts?

Wait please in the near future I will send you mail the new mode in which there will only be combat system, I will do this to check whether the other scripts on the combat.

So look, I created a FULL new mode where I put three scripts. Two for combat and one for data. It is needed to check whether the player has a weapon. Also I put there animations, remote events, and two folders. I also added a script that makes the player square
King Piece, Test.rbxl (58.3 KB)

After some playing around and adding a lot of prints, I did find that the crater function DOES run, there is probably just an issue somewhere in there. Give me some time and I will send a working file back.

Okey, thank you very much, I will wait

I did find one issue that was easily, but only mostly resolved which was very harsh on allowing the crater function to be executed. The if not uis:IsKeyDown(Enum.KeyCode.Space) was preventing it around 99.84% of the time (yes, I calculated it), even when the spacebar was let go of in a matter of a few frames after bringing the rig into the air. After removing that check, it did run every time, but it also ran when it wasn’t supposed to. It resolved it not running, but created the issue of it running when it shouldn’t. I still haven’t found a fix for that.

As well as there were issues with the parts not spawning, despite everything working just fine throughout the function. I haven’t found what’s wrong with that either.

Everything else works just fine as it is, though.


I will continue to look, I promise, but I may not for a while. A good friend of mine just passed away yesterday, and I need some time before I can get myself together enough to continue to help. I will do everything I can to help get this solved!