local remote = game.ReplicatedStorage.Remotes.NoweSciecie
local RR3 = require(game.ServerScriptService.RotatedRegion3)
local module = require(game.ServerScriptService.Siekiery.Scinanie)
remote.OnServerEvent:Connect(function(plr,pozycja,segment,badyl,glowa)
if tostring(segment) == "Drewno" or tostring(segment) == "Sciecie" then
local badylmodule = require(game.ServerScriptService.Siekiery.RodzajeUchwytow:FindFirstChild(badyl))
local minDystansOdDrzewa = badylmodule.dystans
local cooldown
local treeClass
local char = plr.Character
if tostring(segment) == "Drewno" then
treeClass = segment.Parent:FindFirstChild("RodzajDrzewa")
elseif tostring(segment) == "Sciecie" then
treeClass = segment.Parent.Parent:FindFirstChild("RodzajDrzewa")
end
if table.find(badylmodule.specialtreeclasses,treeClass.Value) then
cooldown = badylmodule.specialtreeopoznienie
else
cooldown = badylmodule.opoznienie
end
local cv = plr:FindFirstChild("Cooldown")
if cv.Value == false then
cv.Value = true
if tostring(segment) == "Drewno" then
local plrx = char.HumanoidRootPart.Position.X
local plry = char.HumanoidRootPart.Position.Y
local plrz = char.HumanoidRootPart.Position.Z
local objx = segment.Position.X
local objy = segment.Position.Y
local objz = segment.Position.Z
local calcx = plrx - objx
local calcy = plry - objy
local calcz = plrz - objz
local BeamFirst = calcx^2 + calcy^2 + calcz^2
local BeamTwo = math.sqrt(BeamFirst)
if BeamTwo <= minDystansOdDrzewa then
local przesuniecie = Vector3.new(0,segment.CFrame:pointToObjectSpace(pozycja).Y,0)
local region = RR3.new(segment.CFrame * CFrame.new(przesuniecie),Vector3.new(segment.Size.X+0.02,0.5,segment.Size.Z+0.02))
local parts = region:FindPartsInRegion3()
local sciecie
for i,v in pairs(parts) do
if v.Name == "Sciecie" then
sciecie = v
end
end
if sciecie == nil then
module.noweSciecie(pozycja,segment,badyl,glowa,plr.Name)
else
module.powiekszSciecie(sciecie,segment,badyl,glowa,plr.Name)
end
end
elseif tostring(segment) == "Sciecie" then
local plrx = char.HumanoidRootPart.Position.X
local plry = char.HumanoidRootPart.Position.Y
local plrz = char.HumanoidRootPart.Position.Z
local objx = segment.Position.X
local objy = segment.Position.Y
local objz = segment.Position.Z
local calcx = plrx - objx
local calcy = plry - objy
local calcz = plrz - objz
local BeamFirst = calcx^2 + calcy^2 + calcz^2
local BeamTwo = math.sqrt(BeamFirst)
if BeamTwo <= minDystansOdDrzewa then
module.powiekszSciecie(segment,segment.Parent,badyl,glowa,plr.Name)
end
end
wait(cooldown)
cv.Value = false
end
end
end)