So, I am following a YouTube tutorial from Ampro how to make advanced combat system, but I get a few errors. I can script pretty good and stuff, but I needed a combat system fast for my game.
The script is also located in the starter character scripts as a local script.
Anyways the two errors are in line 55 and 106 in the script.
The error for line 55 is (attempt to compare Vector3 < number) and error for line 106 is Well none but it prints this in the output (Script ‘Workspace.crazygamespp.CombatClient’, Line 106 )
I read somewhere that you can’t compare > or < with vector3. But in the tutorial, he does, and it worked and other people have completed the tutorial. Here is the part of the script I am talking about.
local function HitBox(Size,cframe,ignore,char)
local hb = Instance.new(“Part”,workspace.Fx)
– HitBox Settings
hb.Anchored = true
hb.CanCollide = false
hb.Transparency = .6
hb.Name = “hb”
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) then -- Thats line 55------------------------------------------------
lasttarg = v.Parent.PrimaryPart
end
else
lasttarg = v.Parent.PrimaryPart
end
end
end
hb:Destroy() -- Removes after tuch
if lasttarg then
return lasttarg.Parent
else
return nil
end
end
I think if I solve the error in line 55 then the error in line 106 should also be solved, they are kind of connected.
Here is the Entire Script if you would need it.
– Player Varaibels
local character = script.Parent
local humanoid = character:WaitForChild(“Humanoid”)
local Player = game.Players.LocalPlayer
– Services
local uis = game:GetService(“UserInputService”)
local Rep = game:GetService(“ReplicatedStorage”)
– Remotes
local Remote = Rep:WaitForChild(“Combat”):WaitForChild(“CombatEvent”)
– Varailbels
local LastTimeM1 = 0
local LastEndM1 = 0
local Combo = 1
local CanAirCombo = true
– Animations
local PunchAnims = {
“rbxassetid://11279230611”, – 1
“rbxassetid://11279239813”, – 2
“rbxassetid://11279242294”, – 3
“rbxassetid://11279244603”, – 4
“rbxassetid://11279249053” – 5
}
local AirAnims = {
“rbxassetid://11279262361”, – KickUp
“rbxassetid://11279260266” – SlamDown
}
– Functions
local function HitBox(Size,cframe,ignore,char)
local hb = Instance.new(“Part”,workspace.Fx)
– HitBox Settings
hb.Anchored = true
hb.CanCollide = false
hb.Transparency = .6
hb.Name = “hb”
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) then
lasttarg = v.Parent.PrimaryPart
end
else
lasttarg = v.Parent.PrimaryPart
end
end
end
hb:Destroy() -- Removes after tuch
if lasttarg then
return lasttarg.Parent
else
return nil
end
end
– input
uis.InputBegan:Connect(function(input,gpe)
if gpe then return end – So if the player does a game proceed event the script wont proceed
if input.UserInputType == Enum.UserInputType.MouseButton1 and tick() - LastTimeM1 > 0.3 and tick() - LastEndM1 > 0.7 then
if tick() - LastEndM1 > .7 then
Combo = 1
end
LastTimeM1 = tick()
local animation = Instance.new("Animation", workspace.Fx)
local air = nil
if uis:IsKeyDown("Space") and Combo == 4 and CanAirCombo then
CanAirCombo = false
animation.AnimationId = AirAnims[1]
air = "Up"
elseif not uis:IsKeyDown("Space") and Combo == 5 and not CanAirCombo then
animation.AnimationId = AirAnims[2]
air = "Down"
else
animation.AnimationId = PunchAnims[Combo]
end
local load = humanoid:LoadAnimation(animation)
load:Play()
animation:Destroy()
local hitTarg = HitBox(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"] = "m1"
}
Remote:FireServer(Data)
end
if Combo == #PunchAnims then
Combo = 1
LastEndM1 = tick()
else
Combo +=1
end
humanoid.WalkSpeed = 0
wait(.4)
humanoid.WalkSpeed = 16
end
end)