Here is my code, when I disconnect the event, I don’t want to stop it so it can never be fired again but that is happening, any idea why? I got it to work fine before on different scripts
my code
wait(1)
function GetHuman(Part)
for i, v in pairs(game.Players:GetPlayers()) do
if v and v.Character then
if Part:IsDescendantOf(v.Character) then
return v.Character
end
end
end
if Part and Part.Parent then
if Part.Parent:FindFirstChild("Humanoid") then
return Part.Parent
elseif Part.Parent.Parent:FindFirstChild("Humanoid") then
return Part.Parent
end
end
return nil
end
local CanDmg = false
local Event
Event = script.Parent.RemoteEvent.OnServerEvent:Connect(function(Player,Type,Args)
if Type == "HandleTrans" then
script.Parent.Handle.Transparency = Args
elseif Type == "Stab" then
print("sent")
script.Parent.Handle.Slice:Play()
pcall(function()
CanDmg = true
wait(2)
CanDmg = false
end)
script.Parent.Handle.Touched:Connect(function(hit)
local Humanoid = hit.Parent:FindFirstChildOfClass("Humanoid")
if Humanoid ~= nil and CanDmg == true then
Humanoid:TakeDamage(1000)
end
end)
elseif Type == "Throw" then
script.Parent.Handle.Throw:Play()
local ThrowPart = script.Parent.Handle:Clone()
ThrowPart.CFrame = Player.Character["HumanoidRootPart"].CFrame
ThrowPart.Parent = workspace
ThrowPart.AssemblyLinearVelocity = (Args.Aim - ThrowPart.CFrame.p).unit * 100
local floatingForce = Instance.new('VectorForce')
floatingForce.Force = Vector3.new(0, 196.2 * ThrowPart:GetMass() * 0.98, 0)
floatingForce.RelativeTo = Enum.ActuatorRelativeTo.World
local attach0 = Instance.new("Attachment")
floatingForce.Attachment0 = attach0
attach0.Parent = ThrowPart
floatingForce.Parent = ThrowPart
ThrowPart.AssemblyAngularVelocity = Vector3.new(-ThrowPart.AssemblyLinearVelocity.Z, 0, ThrowPart.AssemblyLinearVelocity.X) *-.1
ThrowPart.Parent = workspace
game.Debris:AddItem(ThrowPart, 5)
ThrowPart:SetNetworkOwner(Player)
local function FinishedThrowing(Hit)
ThrowPart.Anchored = true
if Hit then
if Hit:FindFirstChild("Humanoid") then
Hit.Humanoid:TakeDamage(1000)
game.ServerStorage.Values.PlayersLeft.Value = game.ServerStorage.Values.PlayersLeft.Value - 1
script.Parent.Handle.Kill:Play()
end
end
end
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
raycastParams.IgnoreWater = true
local raycastResult = nil
local StartPosition = script.Parent.Handle.Position
while not raycastResult do
local mag = (ThrowPart.CFrame.p - StartPosition).magnitude
local direction = (ThrowPart.CFrame.p - StartPosition).unit * mag
raycastParams.FilterDescendantsInstances = {Player.Character, ThrowPart}
raycastResult = workspace:Raycast(StartPosition, direction, raycastParams)
if raycastResult then
local Part, position = raycastResult.Instance, raycastResult.Position
local CF = CFrame.new(ThrowPart.CFrame.p, ThrowPart.CFrame.p + ThrowPart.Velocity) * CFrame.Angles(0, 0, math.rad(-90))
local Target = GetHuman(Part)
if Target then
if Target ~= Player.Character then
CF = CF:toObjectSpace(Part.CFrame)
FinishedThrowing(Target)
end
else
ThrowPart.CFrame = CF
FinishedThrowing(Part)
end
end
StartPosition = ThrowPart.CFrame.p
wait()
end
end
Event:Disconnect()
end)