Hello! I’m currently trying to get my gun working after moving to a skinned rig, and i’ve encountered an issue where the hitbox registration no longer works! Could anyone help me with this?
(apologies with the messy code, i haven’t finalised it yet)
Server:
--> Variables
local Tool = script.Parent.Parent
local Structure = Tool:WaitForChild("Structure")
local Values = Tool:WaitForChild("Values")
--> Specific References
local Muzzle = Structure:WaitForChild("Muzzle")
local Particles = Muzzle:WaitForChild("ParticleEmitter")
local Sound = Muzzle:WaitForChild("Sound")
local Health = Values:WaitForChild("Health")
local Blur = Structure:WaitForChild("Blur")
local Fire = Structure:WaitForChild("Fire")
local Enabled = Values:WaitForChild("Enabled")
local Click = Tool.RemoteEvents.Click
local Left = Tool.RemoteEvents.Left
--> General Conditions
local PlayCo = false
--> Double checking that they're disabled!
Particles.Enabled = false
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
raycastParams.FilterDescendantsInstances = {script.Parent.Parent.Parent}
raycastParams.IgnoreWater = true
--> Hitbox Initialisation
--Structure:WaitForChild("Hitbox").Touched:Connect(function() end)
--> let's make it work with the skinned rig
local Character = game.Workspace:WaitForChild(script.Parent.Parent.Parent.Parent.Name)
local function GetTouchingParts(part)
local connection = part.Touched:Connect(function() end)
local results = part:GetTouchingParts()
connection:Disconnect()
return results
end
Character.ChildAdded:Connect(function(child)
if child:IsA("Tool") then
if child.Name == "Flamethrower" then
Enabled.Value = true
end
end
end)
Character.ChildRemoved:Connect(function(child)
if child:IsA("Tool") then
if child.Name == "Flamethrower" then
Enabled.Value = false
end
end
end)
local Weld = Instance.new("WeldConstraint")
Weld.Parent = Character.Base:WaitForChild("ToolPoint")
Weld.Part0 = Character.Base:WaitForChild("ToolPoint")
local sw = coroutine.wrap(function()
while task.wait(0.1) do
script.Parent.Parent.Handle.Position = Character.Base:WaitForChild("ToolPoint").Position
script.Parent.Parent.Handle.Orientation = Character.Base:WaitForChild("ToolPoint").Orientation + Vector3.new(0,90,0)
--script.Parent.Parent.Handle.CFrame = CFrame.new(Character.Base:WaitForChild("ToolPoint").Position) * CFrame.Angles(0, math.rad(90), 0)
end
end)()
Weld.Part1 = script.Parent.Parent.Handle
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RaycastHitbox = require(ReplicatedStorage.RaycastHitboxV4)
--> Activated Tool Function
Click.OnServerEvent:Connect(function(Bool)
print("Recieved")
--> Running a new thread to determine the fuel left
if PlayCo == false then
PlayCo = true
local Co2 = coroutine.wrap(function()
while task.wait(0.1) do
--> If the particles are enabled, we'll subtract a health
if Particles.Enabled == true then
Health.Value = Health.Value - 1
end
--> IIf the health is 0 or below, we'll destroy the tool
if Health.Value <= 0 then
Tool:Destroy()
break
end
task.wait(0.1)
end
end)()
end
--> Enabling Visual Effects
Particles.Enabled = true
Particles.Parent.Sound:Play()
--local OverlapParams1 = OverlapParams.new()
--> Looping for particles enabled
while Particles.Enabled == true do
--[[
local raycastResult = workspace:Raycast(Structure.Hitbox.Position, Structure.Hitbox.CFrame.LookVector * 5, raycastParams)
print(raycastResult)
task.wait(0.1)
--]]
--> Getting the parts touching!
local Parts = Structure.Hitbox:GetTouchingParts()
local Humanoids_Damaged = {}
print("Got Touched")
print(Parts)
--> Prevents crashing by an overly quick loop, while still not feeling clunky
task.wait(0.1)
--> Looping through the touched parts
for i, Part in pairs(Parts) do
print(Part)
--> Seeing if it's a humanoid!
if Part.Parent:FindFirstChild("Humanoid") and not Humanoids_Damaged[Part.Parent.Humanoid] then
print("Found humanoid!")
Humanoids_Damaged[Part.Parent.Humanoid] = true
--> Running a new thread so we don't abstain the rest
local Co = coroutine.wrap(function()
local Number
--> Checking if they're already on fire
if Part.Parent.Humanoid:FindFirstChild("NumberValue") then
Number = Part.Parent.Humanoid:FindFirstChild("NumberValue")
else
Number = Instance.new("NumberValue")
Number.Parent = Part.Parent.Humanoid
end
Number.Value = 15
--> Initialising the fire effect
local D1 = Fire:Clone()
local D2 = Blur:Clone()
--> Parenting the effect to make it visual
D1.Parent = Part.Parent.HumanoidRootPart
D2.Parent = Part.Parent.HumanoidRootPart
--> Dealing Gradual Damage
while Number.Value > 0 do
task.wait(0.1)
Number.Value -= 1
Part.Parent.Humanoid:TakeDamage(1)
end
--> The fire effect is over
D1:Destroy()
D2:Destroy()
end)()
end
end
--]]
end
end)
--> When deactivated, we'll stop the effects
Left.OnServerEvent:Connect(function()
print("left")
Particles.Enabled = false
Particles.Parent.Sound:Stop()
end)
client
local Tool = script.Parent.Parent
local Values = Tool:WaitForChild("Values")
local Enabled = Values:WaitForChild("Enabled")
local UserInputService = game:GetService("UserInputService")
local Click = Tool.RemoteEvents.Click
local Left = Tool.RemoteEvents.Left
UserInputService.InputBegan:Connect(function(inputObject)
if inputObject.UserInputType == Enum.UserInputType.MouseButton1 then
if Enabled.Value == true then
Click:FireServer()
end
end
end)
UserInputService.InputEnded:Connect(function(inputObject)
if inputObject.UserInputType == Enum.UserInputType.MouseButton1 then
if Enabled.Value == true then
Left:FireServer()
end
end
end)
Thanks in advance!