I know this may sound dumb, but I canât hit while moving anymore. Before I used to be able too, now I canât. I believe that it is an animation bug since it animates the tool, Iâm not sure tho. Can anyone help me with this?
I just doing some testing and for some odd reason, in studio, when I specifically âRunâ the game, the raycast works and itâs visualizing. However, when I actually âPlayâ the game in studio there is no raycast and nothing visualized. Is anyone else having this problem or know how to fix this?
Iâve made local script version, using 5 parts inside of the weapon which have to be welded to reference as points so its easily adjustable for all you have to do is have a part inside of a Tool thatâs called Handle, and 5 parts called âRay1â, Ray2"⌠âRay5â. You get the point. After that you should have something like in the video. You also have to create a serverscript that will respond onserverevent of a remoteevent to actually damage the player. To add, removevent doesnt fire when ray hasnât hit player, so the server can only really overload if 1000 players hit a player at the same time With this module you will lag on 100 or less players just hitting air, promise ,since the server is generating all of the rays even they are not hitting anything important.
local runService = game:GetService("RunService")
local Detecting = false
local tool = script.Parent
local Part = {tool:WaitForChild("Ray1"),tool:WaitForChild("Ray2"),tool:WaitForChild("Ray3"),tool:WaitForChild("Ray4"),tool:WaitForChild("Ray5")}
local WS = game:GetService("Workspace")
local Debris = game:GetService("Debris")
local player = game:GetService("Players").LocalPlayer
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {player.Character,tool}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local replicatedStorage = game:GetService("ReplicatedStorage")
local RayHitDetectionEvent = replicatedStorage.RayHitDetection.Hit --create a remote event in a folder called RayHitDetection in replicatedstorage
local RayPart = replicatedStorage.RayHitDetection.Ray --make ray part choose colour and texture rest dont really matter
local RayCooldown = 1--type in seconds
local positionTable = {}
local SecondPositionTable = {}
local u = 0
local rayDelta = os.time()
local SwingDelta = os.time()
local SwingDelay = 3 --seconds
local function VisualiseNonHitRay(rayOrigin,rayDirection,rayDestination, i)
local part = RayPart:Clone()
part.Parent = Part[i]
part.CFrame = CFrame.lookAt(rayOrigin,rayDestination)
part.Size = Vector3.new(0,.1,(rayOrigin-rayDestination).Magnitude)
Debris:AddItem(part, .5)
end
local function CreateRay(rayOrigin,rayDirection,rayDestination, i)
local raycastResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)
if raycastResult then
local hitPart = raycastResult.Instance
if hitPart.Parent then
if hitPart.Parent:FindFirstChild("Humanoid") then
--print("Attacked Humanoid")
if hitPart.Parent == player.Character then
else
if hitPart.Parent.Humanoid.Health>0 then
RayHitDetectionEvent:FireServer(hitPart.Parent)
end
end
end
end
else
VisualiseNonHitRay(rayOrigin,rayDirection,rayDestination, i)
end
end
function RayHitbox()
rayDelta=os.time()
while Detecting==true do
for i,v in pairs (Part) do
positionTable[i] = v.Position
end
u=u+1
runService.RenderStepped:Wait()
for i,v in pairs (Part) do
SecondPositionTable[i] = v.Position
end
for i,v in pairs(positionTable) do
if (v-SecondPositionTable[i]).Magnitude > math.pi then
else
CreateRay(v,SecondPositionTable[i]-v,SecondPositionTable[i], i)
end
end
if u == RayCooldown*60 then
u=0
Detecting=false
coroutine.yield()
end
if os.time()-RayCooldown>rayDelta then
rayDelta=os.time()
Detecting=false
coroutine.yield()
end
end
coroutine.yield()
end
local function Start()
if os.time()-SwingDelay > SwingDelta then
SwingDelta = os.time()
Detecting = true
local Rays = coroutine.create(RayHitbox)
coroutine.resume(Rays)
end
end
tool.Equipped:Connect(function()
tool.Activated:Connect(Start)
end)
âEdits, just improved a bit of code so you couldnât press down and keep damaging people
Every time I try using HitStart() it just spits out a error saying âattempt to call a nil valueâ. Nobody else seems to be having this issue, so I have no idea what Iâm doing wrong.
I literally copied the code from the GitHub tutorial with zero edits and keep getting an âattempt to index nilâ error. I have the module in ReplicatedStorage and have a part with attachments just like the tutorial (taking things step by step to make sure itâs all working, which it isnât) so I have no clue what Iâm doing wrong. Might just try to write my own code from scratch at this rateâŚ
Can you get hitboxes on client side? My hitbox was created on server side, and i was wondering if you can interact with it on client.
Event.OnClientEvent:Connect(function(vizualize: BoolValue, HitboxObject)
local hitbox = HitboxModule:GetHitbox(HitboxObject)
if hitbox~=nil then
hitbox.Visualizer=vizualize
else
warn("No hitbox found!")
end
end)
Did you mean so the client will see all the other players hitboxes including his own?
If not:
Make the hitboxes be visualized on client instead of using debug mode