#Combat script working weird
1 messages · Page 1 of 1 (latest)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local combatEvent = ReplicatedStorage:FindFirstChild("RemoteEvent"):FindFirstChild("CombatEvent")
local SS = game:GetService("SoundService")
local damage = 10
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local combatStatus = Instance.new("StringValue", character)
combatStatus.Name = "CombatStatus"
combatStatus.Value = ""
local hitbox = Instance.new("Part", character.HumanoidRootPart)
local weldConstraint = Instance.new("WeldConstraint", hitbox)
hitbox.Name = "Hitbox"
hitbox.Anchored = false
hitbox.Massless = true
hitbox.CanCollide = false
hitbox.Transparency = 1
hitbox.Size = Vector3.new(30,38,30)
hitbox.Color = Color3.new(1,0,0)
hitbox:PivotTo(character.HumanoidRootPart.CFrame)
weldConstraint.Part0 = hitbox
weldConstraint.Part1 = character.HumanoidRootPart
end)
end)
combatEvent.OnServerEvent:Connect(function(player, eventType, arg1)
local character = player.Character
if eventType == "M1" and character.CombatStatus.Value == "" then
character.CombatStatus.Value = "Attacking"
local At = character.Humanoid:LoadAnimation(script[arg1])
At:Play()
SS.Swoosh:Play()
local startPosition = character.HumanoidRootPart.Hitbox.Position
local direction = character.HumanoidRootPart.Hitbox.CFrame.LookVector
local RayCastParams = RaycastParams.new()
RayCastParams.FilterType = Enum.RaycastFilterType.Exclude
RayCastParams.FilterDescendantsInstances = character:GetDescendants()
local ray = workspace:Raycast(startPosition, direction * 100, RayCastParams)
if ray and ray.Instance and ray.Instance.Parent:FindFirstChild("Humanoid") then
local enemyCharacter = ray.Instance.Parent
local random = math.random(1,2)
SS.Hit:Play()
enemyCharacter.Humanoid.Health -= damage
end
At.Ended:Connect(function()
character.CombatStatus.Value = ""
end)
end
end)
if ur hitbox is werid try using a os hitbox module
usually don’t use a ray for m1 strings
Like G1C said don't use rays for m1 hitboxes and i would also recommend not playing animations on the server. Here is a tutorial that goes over multiple ways you can create hitboxes in roblox https://youtu.be/-oVHaPCOIf4?si=-3-kKNlP9kaLcUBE
A quick tutorial on making good hitboxes in Roblox Studio
ShapecastHitbox: https://devforum.roblox.com/t/shapecasthitbox-for-all-your-melee-needs-v025/3624241
BetterReplication: https://devforum.roblox.com/t/betterreplication-vastly-improve-your-combat-experience-by-fighting-lag/3260027
SecureCast: https://devforum.roblox.com/t/archived-secur...