Hi guys.
I have tried to make player cannon, but it not works. The point where I apply velocity to player. If I apply it on client - it works, but when on server - it decides to ignore it. How I can fix this?
function ModuleMeta:Fire(Occupant)
local CurTime = DateTime.now().UnixTimestampMillis/1000
--always continues further for testing speed.
if false and CurTime - self.Debounce < 15 then return false, "Wait a bit." end
local Character = Occupant.Character
if not Character then return false, "No character found" end
self.Debounce = CurTime
coroutine.wrap(function()
local Seat = self.Object.Seat
local Root = Character.HumanoidRootPart
Character:PivotTo(Seat.CFrame)
for _, Part in Character:GetDescendants() do
if Part:IsA("BasePart") then
Part:SetNetworkOwner(nil)
end
end
local Weld = Instance.new("WeldConstraint")
Weld.Name = "SeatWeld"
Weld.Part0 = Seat
Weld.Part1 = Root
Weld.Parent = Seat
Libraries.AntiCheat.AddExcuse(Occupant, "CannonFire", {
Time = CurTime-1,
Expire = CurTime+15,
Target = function(Penalty)
if Penalty.Data.Type == "Teleport" then
return true
end
return false
end,
})
Remotes.CharacterEvent:FireClient(Occupant, "CamLock", {State = true})
task.wait(3)
Weld:Destroy()
local Emitter = self.Object.ConfettiEmitter
Libraries.CharacterActions.ActivateEffect("Ragdoll", Character, true, nil)
local Temp = {}
local Uncollide = Instance.new("NoCollisionConstraint")
Uncollide.Part0 = self.Object.CannonBase
local Velocity = Seat.CFrame.UpVector*self.Power
for _, Part in Character:GetDescendants() do
if Part:IsA("BasePart") then
local Constraint = Uncollide:Clone()
Constraint.Part1 = Part
Constraint.Parent = self.Object.Constraints
table.insert(Temp, Constraint)
Part.AssemblyLinearVelocity = Velocity
end
end
task.wait(0.5)
for _, Constraint in Temp do
Constraint:Destroy()
end
for _, Part in Character:GetDescendants() do
if Part:IsA("BasePart") then
Part:SetNetworkOwner(Occupant)
end
end
Temp = {}
task.wait(2.5)
Libraries.CharacterActions.ActivateEffect("Ragdoll", Character, false, nil)
Remotes.CharacterEvent:FireClient(Occupant, "CamLock", {State = false})
end)()
return true
end