Hey all,
I am making a plane kit, and it was almost complete, but I ran into problems because everything functioned on a single local script so none of the weapons or anything worked for people other then the local player.
Keep in mind i’ve got about only 5 months scripting experience, but I managed to re-write the entire plane today to send all the inputs and stuff to a server script to make the weapons fire, etc. Works great right? right??
Well, no. In fact it’s awful. Before the guns fired crisp and quick:
But now, everything is handled by a server script:
As you can see, the guns worked beautifully when handled by the client script, because it was lag-free. Of course I was overwhelmed by this because with only a few months of scripting knowledge, I can’t seem to find a way out. But when I reached out to fellow developers, I was recommended Networking Ownership to combat the projectile lag, but this doesn’t improve it, as it makes the problem even worse.
I was then recommended raycasting, and as of right now, it seems like the only viable solution. Why didn’t games from years ago struggle with this projectile lag!?!
Problem is, with my lack of knowledge, I have no idea what raycasting is. There is no way I am able to do this. I can’t even fathom where to start, nor will I be able to quickly. This will take a while, as it touches on so many things I haven’t ever seen before. I’ve never ever even used a module script.
I’d love for them to have the same functionality as the guns from Zepplin Wars:
Everything about my guns work except for the fact that the projectiles lag now because it is handled by a server script. All I need to do is convert it from it’s current state into raycasting, but I have no idea where to even begin.
Here is my code:
elseif Type == "MachineGun" then
print("server caught machine gun")
local CurrentSpawn = Weapons:findFirstChild("MachineGun"..tostring(CurrentBullet))
if CurrentSpawn then
if machinegun.Value > 0 then
machinegun.Value = machinegun.Value - 1
local Part = Instance.new("Part")
Part.BrickColor = BrickColor.new("Pearl")
Part.Transparency = 0.3
Part.Material = "Neon"
Part.Name = "Bullet"
Part.CanCollide = false
Part.Shape = "Block"
Part.FormFactor = "Symmetric"
Part.Size = Vector3.new(1.3, 1.3, 14)
local bulletmesh = Instance.new("SpecialMesh")
bulletmesh.MeshType = "Sphere"
bulletmesh.Scale = Vector3.new(1, 1, 1)
bulletmesh.Parent = Part
local BV = Instance.new("BodyVelocity")
BV.Parent = Part
BV.maxForce = Vector3.new(math.huge,math.huge,math.huge)
local PlaneTag = Instance.new("ObjectValue")
Sounds.Gunshot:Play()
PlaneTag.Parent = Part
PlaneTag.Name = "PlaneTag"
PlaneTag.Value = engine
local value = math.random(1,#bullettable)
local picked_value = bullettable[value]
local bsound = Sounds:FindFirstChild(picked_value.Name)
local sound = bsound:Clone()
sound.Parent = Part
Part.Touched:connect(function(Object)
sound:Play()
if (not Object:IsDescendantOf(char)) then
local HitHumanoid = Object.Parent:findFirstChild("Humanoid")
local Hitplayer = Players:GetPlayerFromCharacter(Object.Parent)
if HitHumanoid then
if Hitplayer.Team ~= player.Team then
HitHumanoid:TakeDamage(15)
local CreatorTag = Instance.new("ObjectValue")
CreatorTag.Name = "creator"
CreatorTag.Value = player
CreatorTag.Parent = HitHumanoid
end
elseif (not HitHumanoid) then
if player.Team == blue then
if Object.Parent.Parent.Team.Value == "Red" then
Object.Parent.Parent.Hp.Value = Object.Parent.Parent.Hp.Value - 5
Sounds.Hitmarker:Play()
Part:Destroy()
elseif Object.RedBase then
Object.RedBase.Health.Value = Object.Redbase.Health.Value - 5
Sounds.Hitmarker:Play()
Part:Destroy()
end
elseif player.Team == red then
if Object.Parent.Parent.Team.Value == "Blue" then
Object.Parent.Parent.Hp.Value = Object.Parent.Parent.Hp.Value - 5
Sounds.Hitmarker:Play()
Part:Destroy()
elseif Object.BlueBase then
Object.BlueBase.Health.Value = Object.Bluebase.Health.Value - 5
Sounds.Hitmarker:Play()
Part:Destroy()
end
end
end
end
end)
Part.Parent = game.Workspace
Part:SetNetworkOwner(nil)
Part.CFrame = CurrentSpawn.CFrame + CurrentSpawn.CFrame.lookVector * 10
BV.velocity = (CurrentSpawn.Velocity) + (Part.CFrame.lookVector * 2000) + (Vector3.new(0,0.15,0))
coroutine.resume(coroutine.create(function()
wait(5)
Part:Destroy()
end))
CurrentBullet = CurrentBullet + 1
CurrentBullet = (CurrentBullet > 2 and 1 or CurrentBullet)
end
end
end
If someone is able to help me with this I would be so grateful.
Thanks,
John