With my flamethrower, you can right click to fire out a gas canister. Enemies within the canister's range take damage.
When I fire the canister and it hits a surface, it anchors itself, 'sticking' to it. However, on the server, it appears that the projectile is travelling slower and is anchored mid-air. I believe that, when it hits a surface on the client, it anchors it on the server even if the server hasn't caught up yet. I tested this in Studio's Local Server with 3 other players controlled by me - maybe this is the reason for the delay? Looking at the server window when I fire the gun, the projectile is really slow and laggy. (edit: this occurs on normal servers too)
Here is the gas canister script within the flamethrower:
local missile = game.ReplicatedStorage.Weapons.GasBomb:Clone()
missile.Parent = game.Workspace
-- this isn't named "Spark"!
missile.BrickColor = BrickColor.new(361)
missile.BottomSurface = 0
missile.TopSurface = 0
missile.CFrame = BulletCF + Direction * 3
missile.Velocity = Direction * 120
missile.Owner.Value = Player.Name -- if you want SUPERB optimisation, replace these - you already have the values.
missile.TeamColor.Value = Player.TeamColor
Handle.AlternateFireSound:Play()
local debounce = false
local activated = false
missile.Touched:connect(function(hit)
if hit.CanCollide == true and hit.Parent:FindFirstChild("Humanoid") == nil then -- don't 'hit' players.
if hit.Transparency ~= 1 and hit.Parent.Name ~= "PlayerFolder" and hit.Parent ~= Player.Character then
if hit.Name ~= Gun.TeamSpawnPartToIgnore.Value and not(hit.Parent:IsA("Tool")) and not(hit.Parent:IsA("Accessory")) then
if debounce == false and activated == false then
missile.CustomPhysicalProperties = PhysicalProperties.new(100,0,0,0.1,100) -- stop floating balls
debounce = true
activated = true
debounce = false
if tostring(Player.TeamColor) == "Bright red" then
missile.RedSmoke.Enabled = true
else
missile.BlueSmoke.Enabled = true
end
missile.GasSound:Play()
print("releasing the gas!")
gas = nil
gas = Instance.new("Part")
gas.CanCollide = false
gas.Name = math.random(0,100000)
gas.Parent = missile
gas.Size = Vector3.new(25,25,25)
gas.Transparency = 1
gas.Shape = 0
gas.BottomSurface = 0
gas.TopSurface = 0
gas.Elasticity = 0
gas.Friction = .9 -- need to weld
gas.CFrame = missile.CFrame
gas.Anchored = true
missile.Anchored = true
local destroysound = Handle.DestroySound:Clone()
destroysound.Parent = missile
destroysound.PlayOnRemove = true
spawn(function()
wait(12)
gas:Destroy()
while wait(0.1) do
missile.RedSmoke.Rate = missile.RedSmoke.Rate - 2.5
missile.BlueSmoke.Rate = missile.RedSmoke.Rate - 2.5
if missile.RedSmoke.Rate == 0 then
wait(2)
missile.Transparency = missile.Transparency + 0.1
wait(0.005)
missile.Transparency = missile.Transparency + 0.1
wait(0.005)
missile.Transparency = missile.Transparency + 0.1
wait(0.005)
missile.Transparency = missile.Transparency + 0.1
wait(0.005)
missile.Transparency = missile.Transparency + 0.1
wait(0.005)
missile.Transparency = missile.Transparency + 0.1
wait(0.005)
missile.Transparency = missile.Transparency + 0.1
wait(0.005)
missile.Transparency = missile.Transparency + 0.1
wait(0.005)
missile.Transparency = missile.Transparency + 0.1
wait(0.005)
missile:Destroy()
break
end
end
end)
gas.Touched:connect(function(otherPart)
if otherPart.Parent:FindFirstChild("Humanoid") ~= nil then
local player = game.Players:GetPlayerFromCharacter(otherPart.Parent)
if otherPart.Parent.Name ~= "PlayerFolder" and otherPart.Parent.Name ~= "Fake_Model" then
if player == nil then -- if an npc
if otherPart.Parent.Humanoid:FindFirstChild(gas.Name) == nil and gassed == false then
gassed = true
local hurtscript = Handle.HurtScript:Clone()
hurtscript.Name = gas.Name
hurtscript.Parent = otherPart.Parent.Humanoid
hurtscript.Disabled = false
local ownerclone = missile.Owner:Clone()
ownerclone.Parent = hurtscript
gassed = false
end
elseif player.TeamColor ~= Player.TeamColor then
if otherPart.Parent.Humanoid:FindFirstChild(gas.Name) == nil and gassed == false then
gassed = true
local hurtscript = Handle.HurtScript:Clone()
hurtscript.Name = gas.Name
hurtscript.Parent = otherPart.Parent.Humanoid
hurtscript.Disabled = false
local ownerclone = missile.Owner:Clone()
ownerclone.Parent = hurtscript
gassed = false
end
end
end
end
end)
gas.TouchEnded:connect(function(otherPart)
if otherPart.Parent:FindFirstChild("Humanoid") ~= nil then
if otherPart.Parent.Humanoid:FindFirstChild(gas.Name) ~= nil then
otherPart.Parent.Humanoid:FindFirstChild(gas.Name):Destroy()
end
end
end)
end
end
end
end
end)
Thanks!

1 comment
That makes no sense cus whatever happens on the server should replicate exactly. If you are doing this stuff client-side, don't.