I have a question, I am unable to make my ClientCast work properly when the client cast starts everything but the damage portion works, it’s not detecting the humanoid of other players/dummies, therefore, it’s not doing any damage. Here’s my code please let me know what I’m doing wrong?
game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
print('CharacterAdded')
local PropWep = WepFolder.PropWep:Clone()
PropWep:SetPrimaryPartCFrame(Character.UpperTorso.CFrame * CFrame.new(0,0,-0.60))
PropWep.Parent = Character
local Motor6D = Instance.new('Motor6D')
Motor6D.Name = "HandWeld"
Motor6D.Part0 = Character.PrimaryPart
Motor6D.Part1 = PropWep.PrimaryPart
Motor6D.C0 = CFrame.new(Vector3.new(0,0,0.60)) * CFrame.Angles(0,0,math.rad(45))
Motor6D.Parent = PropWep
local raycastparams = RaycastParams.new()
local Debounce = {}
raycastparams.FilterDescendantsInstances = {Character}
raycastparams.FilterType = Enum.RaycastFilterType.Blacklist
ClientCaster = ClientCast.new(PropWep, raycastparams)
local Character = Player.Character or Player.CharacterAdded:Wait()
ClientCaster.Collided:Connect(function(RaycastResult, HitHumanoid)
print('before')
if IsEquipped and debounce[HitHumanoid] then
return
end
print('After')
debounce[HitHumanoid] = true
IsEquipped = true
HitHumanoid:TakeDamage(10)
wait(0.5)
debounce[HitHumanoid] = false
IsEquipped = false
print('Swing')
end)
ClientCaster:Start()
ClientCaster:StartDebug()
end)
end)
I recommend you isolate as much of your code as possible and make a script which reproduces the issue in as little lines as possible. From there, it will be easier to see what the bug is.
I appreciate you so much for this! This is absolutely awesome. Can i ask a question? Where does this script go?
-- Call module
local ClientCast = require(PATH.ClientCast)
-- Create ClientCaster object
local Caster = ClientCast.new(workspace.Part, RaycastParams.new())
-- Connect callback to 'Collided' event
Caster.Collided:Connect(print)
-- Set owner of ClientCaster, who will be the one to calculate collisions.
-- You can skip this if you want the server to be the owner.
Caster:SetOwner(Player)
-- Start detecting collisions
Caster:Start()
i was reading your post on github and i dont really understand where to put this script at. Any help is greatly appreciated.
Forgive me if im not the smartest but if im doing it correctly:
The clientcast module script goes in “ServerStorage”
-- Call module
local ClientCast = require(PATH.ClientCast)
-- Create ClientCaster object
local Caster = ClientCast.new(workspace.Part, RaycastParams.new())
-- Connect callback to 'Collided' event
Caster.Collided:Connect(print)
-- Set owner of ClientCaster, who will be the one to calculate collisions.
-- You can skip this if you want the server to be the owner.
Caster:SetOwner(Player)
-- Start detecting collisions
Caster:Start()
this script goes in “serverstorage”
local ClientCast = require(game.ServerStorage.ClientCast)
local KillPart = Instance.new('Part')
KillPart.Anchored = true
KillPart.CanCollide = false
KillPart.CFrame = CFrame.new(0, 1, 0)
KillPart.Parent = workspace
function GenerateAttachment(Position)
local Attachment = Instance.new('Attachment')
Attachment.Name = 'DmgPoint'
Attachment.Position = Position
Attachment.Parent = KillPart
end
for X = -2, 2 do
GenerateAttachment(Vector3.new(X, Y, Z))
end
local ClientCaster = ClientCast.new(KillPart, RaycastParams.new())
local Debounce = {}
ClientCaster.HumanoidCollided:Connect(function(RaycastResult, HitHumanoid)
if Debounce[HitHumanoid] then
return
end
Debounce[HitHumanoid] = true
print('Ow!')
HitHumanoid:TakeDamage(10)
wait(0.5)
Debounce[HitHumanoid] = false
end)
ClientCaster:Start()
and this script goes in serverscriptservice i believe?
Then i just add DmgPoints as attachments.
Add a simple debounce. An example would be like so:
local DamagedHumanoid = nil
ClientCaster.HumanoidCollided:Connect(function(RaycastResult, HitHumanoid)
ClientCaster:Stop()
DamagedHumanoid = HitHumanoid
end)
task.wait(2)
ClientCaster:Stop()
if DamagedHumanoid then
...
end
How would i add an option for the player to visualize only his own hitboxes? What i mean is for the player to flick a setting on or off and that input will correspond to if they will see their own hitbox lines or not
Just running the humanoid collided event with no internal checks, a humanoid is not always detected on the hit, even when they are clearly hit by the weapon/rays. If anyone else has experienced this, and/or has a possible solution, please let me know.
local Caster = ClientCast.new(tool.Blade, raycastParams)
local hitTable = {}
-- Connect callback to 'Collided' event
Caster.HumanoidCollided:Connect(function(RaycastResult, HitHumanoid)
print(HitHumanoid.Parent.Name)
--Calcuate and deal damage based on weapon and active buffs/debuffs
--DamageModule.DealDamageBasic(tool.Name, player, HitHumanoid, character, hitTable, toolInfo.Damage)
end)
-- Set owner of ClientCaster, who will be the one to calculate collisions.
-- You can skip this if you want the server to be the owner.
Caster:SetOwner(player)
-- Start detecting collisions
Caster:Start()
task.wait(toolInfo.Cooldown - 0.2)
-- Stop the caster object / collisions detections
Caster:Stop()
I can’t really help without having a way to reproduce the issue. I recommend you try isolating the problem, and finding as consistent a repro as possible. This would help a lot in fixing the bug!
Well the issue I’m having is with me running the module bare bones, with nothing else in the back ground. I am however, accessing the module from the server, which honestly isn’t really a great idea for combat, and may be the cause of the discrepancies. I’ll try testing the system locally instead.
That’s the intended use of the module! It handles client <–> server communication for you, so you can just set up hitboxes on server, have them calculated on client, and sent back to server. Depending on how big the hitbox inaccuracy may be, perhaps it could be attributed to network lag?
Well the issue persists even in local play test servers against stationary player characters with fairly optimal performance. I’ll run some extensive tests when I have time.
Not to be rude, it could simply be an issue with how I setup the system, but after moving over to the raycast hitbox, all hits were detected. If anyone else ends up having similar issues to what I was having I could maybe dig deeper and try to be a bit more helpful. One thing I will note is that I setup the hitboxes on the client using the rh4 module, over on the server as I did with yours.
Also i’ve seen others mention this; however, the detections seemed worse when I had attacking animations that caused the dmgpoints to intersect the player wielding the weapon. Hence, it may have been an issue with the module registering the attacker’s character and then jumping out of the hitdetection system, without continuing checks. (Just speculations though)
Well, as mentioned in the thread this module is meant to be very barebones in order to allow for maximum customization for the end user - this comes with a downside of being complex for those not as familiar, or to those who don’t need overly dynamic behavior.
Unsure if you’re referring to this module or rh4, but ClientCast has no built-in debounces, nor does it differentiate the weapon wielder from other targets. It shouldn’t stop raycasting when it hits a target, only when you explicitly call either:Stop or :Destroy.