Unless a tool is in starter pack, if it is cloned to the backpack, I cant slap people. Everything until the tool is activated works though. The tool has data and all so I am a little confused
--// SERVICES
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Debris = game:GetService("Debris")
local ServerStorage = game:GetService("ServerStorage")
local Players = game:GetService("Players")
local ServerScriptService = game:GetService("ServerScriptService")
--// FOLDERS
local modules = ServerScriptService.Modules
local Tools = ServerStorage.Tools
local Events = ReplicatedStorage.Events
--// REFRENCES
local SlapData = require(modules.SlapData)
local SlapAnim = Events.SlapAnim
--// TYPES
type SlapTool = {
Handle: MeshPart,
Smack: Sound,
HitBox: Part
}
type slapData = {
FLING_FORCE: number,
COOLDOWN_TIME: number,
VECTOR: Vector2,
HIT_WINDUP: number,
HIT_WINDOW: number
}
local Service = {}
function Service.DetectAndApplyHit(character: Model, slapTool: SlapTool, data: slapData, hitVictims: {Model})
local playerHRP = character:FindFirstChild("HumanoidRootPart")
if not playerHRP then return end
local hitbox = slapTool.HitBox
local overlapParams = OverlapParams.new()
overlapParams.FilterType = Enum.RaycastFilterType.Exclude
overlapParams.FilterDescendantsInstances = { character }
local touchingParts = workspace:GetPartBoundsInBox(hitbox.CFrame, hitbox.Size, overlapParams)
for _, part in ipairs(touchingParts) do
local model = part:FindFirstAncestorWhichIsA("Model")
local targetHrp = model and model:FindFirstChild("HumanoidRootPart")
if model and model ~= character and targetHrp and not table.find(hitVictims, model) then
table.insert(hitVictims, model)
slapTool.Handle.Smack:Play()
local attachment = Instance.new("Attachment", targetHrp)
local linVelo = Instance.new("LinearVelocity")
linVelo.Attachment0 = attachment
local direction = playerHRP.CFrame.LookVector * data.VECTOR.X + Vector3.new(0, data.VECTOR.Y)
linVelo.VectorVelocity = direction
linVelo.MaxForce = 9999
linVelo.Parent = targetHrp
Debris:AddItem(linVelo, 0.2)
task.spawn(function()
model:SetAttribute("Ragdoll", true)
task.delay(2, function()
model:SetAttribute("Ragdoll", false)
end)
end)
end
end
end
function Service.GetSlap(slapName)
local data = SlapData[slapName]
if not data then return nil end
return {
FLING_FORCE = data.FLING_FORCE or 75,
COOLDOWN_TIME = data.COOLDOWN_TIME or 1,
VECTOR = data.VECTOR or Vector2.new(1, 0.5),
HIT_WINDUP = data.HIT_WINDUP or 0.15,
HIT_WINDOW = data.HIT_WINDOW or 0.3,
}
end
function ApplySlap(location)
for _, tool: Tool in location:GetChildren() do
if not tool:IsA("Tool") or tool:GetAttribute("SlapConnected") then continue end
local slapInfo = Service.GetSlap(tool.Name)
if not slapInfo then continue end
print(tool.Name)
tool:SetAttribute("SlapConnected", true)
local onCD = false
print("GOT HERE")
tool.Activated:Connect(function()
print("ACTIVATED")
if onCD then return end
onCD = true
print(tool.Name)
local character = tool.Parent
local player = Players:GetPlayerFromCharacter(character)
if not player then
onCD = false
return
end
print("Far")
SlapAnim:FireClient(player)
print("FIRED")
local hitVictimsThisSwing = {}
task.wait(slapInfo.HIT_WINDUP)
local elapsedTime = 0
while elapsedTime < slapInfo.HIT_WINDOW do
Service.DetectAndApplyHit(character, tool, slapInfo, hitVictimsThisSwing)
elapsedTime += task.wait()
end
task.wait(slapInfo.COOLDOWN_TIME)
onCD = false
end)
end
end
function Service.Init()
ApplySlap(Tools)
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local backpack = player:WaitForChild("Backpack")
ApplySlap(character)
ApplySlap(backpack)
backpack.ChildAdded:Connect(function(child)
if child:IsA("Tool") then
ApplySlap(child)
end
end)
character.ChildAdded:Connect(function(child)
if child:IsA("Tool") then
ApplySlap(child)
end
end)
end)
end)
end
return Service