Even with removing the beam, the effect glitch is not fixed
What is causing that beam then?
I have already removed the beam. Im saying that the debris effect when the bullet hits something still lags. Might be the amount of raycasting cause its piercing alo
Nah, raycasting does not cause performance dips. I think its rather the bullet hole effect, since they are having to be created everytime the you fire.
They are made with surface guis, so it cant be
I recommend you look into a different post about handling game lag, its out of my expertise
I do hope i was help though
EDIT:
https://developer.roblox.com/en-us/articles/Improving-Performance
I’ve had a look at them now, none of them seems to help but the steaming bit is interesting as I’ve never heard of something like it!
Can you list me the scripts that are running on the server and scripts running in the client?
Server:
local data=Instance.new("Folder",p)
data.Name='data'
local team=Instance.new('StringValue')
team.Name='team'
team.Value=p.Name
team.Parent=data
end)
game.ReplicatedStorage:WaitForChild("events").takeDmg.OEvent:connect(function(p,dmg,hum)
if hum.Parent==p.Character then
return
end
if game.Players:GetPlayerFromCharacter(hum.Parent)then
for i,v in pairs(game.Players:players())do
if v.data.team.Value==p.data.team.Value then
if v.Character then
if hum==v.Character.Humanoid then
return
end
end
end
end
end
hum:takeDamage(dmg)
end)
bruh why is it not formatting properly
Gun Server:
local shoot_part = tool:WaitForChild("muzzle")
local remote = tool:WaitForChild("shootEvent")
local ServerStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ReloadDebounce = false
local rpm = 600
local bul = require(game.ReplicatedStorage.BulletHoles)
local fire
local RandomValue = function(Argument1, Argument2)
return Random.new():NextNumber(Argument1 or -.1, Argument2 or .1) --Custom Random function cause math.random isent really working for me
end
math.randomseed(tick())
fire = function(player,data)
local ray = RaycastParams.new()
ray.FilterType = Enum.RaycastFilterType.Blacklist
local ignore = {
data.sender.Character,
workspace.ignoreList
}
for i, v in pairs(game.Players:players()) do
if v.data.team.Value == data.sender.data.team.Value and v ~= data.sender then
table.insert(ignore, #ignore + 1, v.Character)
end
end
ray.FilterDescendantsInstances = ignore
local gun = data.tool
local position = data.pos + Vector3.new(RandomValue(-.3, .3), RandomValue(-.3, .3), RandomValue(-.3, .3))
local origin = data.org.Position
local direction = (position - origin).Unit * 300
local result = workspace:Raycast(origin, direction, ray)
local intersection = result and result.Position or origin + direction
local distance = (origin - intersection).Magnitude
game.ReplicatedStorage.events.cam:FireAllClients('recoil', {
dist = distance,
sender = player
})
if distance>200 then
local beamStart = Instance.new("Attachment")
local beamEnd = Instance.new("Attachment")
beamStart.Parent, beamEnd.Parent = workspace.Terrain, workspace.Terrain-- a hack bc the terrian counts as an infinite basepart
beamStart.Position, beamEnd.Position = origin, intersection
local beam = script.Beam:clone()
beam.Enabled = true
beam.Attachment0 = beamStart
beam.Attachment1 = beamEnd
beam.Parent = beamStart
local time = .2 + (distance / 200)
beam.TextureSpeed = 5 - (time * 10)
game:GetService("TweenService"):Create(beamStart, TweenInfo.new(time), {
Position = beamEnd.Position
}):Play()
game:GetService("Debris"):AddItem(beamStart, time)
game:GetService("Debris"):AddItem(beamEnd, time)
end
local hit = Instance.new("Part")
hit.Name = 'hit_sfx'
hit.Anchored = true
hit.CanCollide = false
hit.Transparency = 1
hit.Position = intersection
hit.Size = Vector3.new(.05, .05, .05)
hit.Parent = workspace.ignoreList
game:GetService("Debris"):AddItem(hit, 1.5)
local sfx = script['Bullet_sound_'..math.random(1, 6)]:Clone()
sfx.Parent = hit
sfx:Play()
for i, v in pairs(gun.muzzle.effects:children()) do
v:Emit(10)
end
local sfx = gun.muzzle.fire:clone()
sfx.Parent = gun.muzzle
sfx:play()
game.Debris:AddItem(sfx, 3)
if result then
local part = result.Instance
local humanoid = part.Parent:FindFirstChild("Humanoid") or part.Parent.Parent:FindFirstChild("Humanoid")
if humanoid then
if p == data.sender then
game.ReplicatedStorage.events.takeDmg:fire(data.damage, humanoid)
end
local hit = result.Instance
local hole = bul:New(hit, intersection, 1, 'rbxassetid://5427017132')
local DebrisAttachment = Instance.new("Attachment", workspace.Terrain)
DebrisAttachment.Position = intersection
local DebrisEffect = game.ReplicatedStorage.hit:Clone()
local Effect = DebrisEffect
Effect.Enabled = true
Effect.Parent = DebrisAttachment
coroutine.resume(coroutine.create(function()
wait(.2)
Effect.Enabled = false
wait(1)
DebrisAttachment:Destroy()
end))
local DebrisAttachment = Instance.new("Attachment", workspace.Terrain)
DebrisAttachment.Position = intersection
local DebrisEffect = game.ReplicatedStorage.spray:Clone()
local Effect = DebrisEffect
Effect.Enabled = true
Effect.Parent = DebrisAttachment
wait(1)
Effect.Enabled = false
wait(4)
DebrisAttachment:Destroy()
else
local hit = result.Instance
local hole = bul:New(hit, intersection, 1)
local DebrisAttachment = Instance.new("Attachment", workspace.Terrain)
DebrisAttachment.Position = intersection
local spark = script.Spark:clone()
spark.Parent = DebrisAttachment
spark:emit(10)
local DebrisEffect = game.ReplicatedStorage.debris:Clone()
local Effect = DebrisEffect
Effect.EmissionDirection = hole.Face
Effect.Color = ColorSequence.new(result.Instance.Color)
Effect.Enabled = true
Effect.Parent = DebrisAttachment
local xyz={ -- store the imfo of the faces.
['Enum.NormalId.Top']='Y';
['Enum.NormalId.Bottom']='Y';
['Enum.NormalId.Left']='X';
['Enum.NormalId.Right']='X';
['Enum.NormalId.Front']='Z';
['Enum.NormalId.Back']='Z';
}
local axis=xyz[tostring(hole.Face)] -- eg. if the face is the top, look at the Y axis scale
local thickness=hit.Size[axis]
print(axis)
print(thickness)
if thickness<=1 then -- if its smaller than 1, pierce
print('pierce it!')
local data=data
local p = Instance.new("Part") -- get a part for the origin direction and destroy it after 1.5 seconds
p.Name = 'pierce'
p.Anchored = true
p.CanCollide = false
p.Transparency = 1
p.CFrame = CFrame.new(intersection,origin)
p.CFrame=p.CFrame * CFrame.Angles(0,math.rad(180),0) * CFrame.new(0,0,-thickness)
p.Size = Vector3.new(.05, .05, .05)
p.Parent = workspace.ignoreList
game:GetService("Debris"):AddItem(p,1.5)
data.org=p
data.pos=p.CFrame.LookVector*300 -- change the position and origin
fire(data) -- continue
end
wait(.5)
Effect.Enabled = false
game.Debris:AddItem(DebrisAttachment, 2)
end
end
end
remote.OnServerEvent:Connect(function(player, type, data)
if type == 'whenActivated' then
data['rpm'] = rpm
fire(player,data)
end
end)```
Oh god i see the issue, remove all prints
If you print a lot it actually causes lag
EDIT: Is it fixed, if so I can help you quickly stress test it to see if it will lag.
yes, i added this to make it only print in studio.
local echo=print
getfenv().print=function(message)if game:GetService(“RunService”):IsStudio()then ehco(message)end end
Ok if you want to i can check the end result and see if it needs anything. I will gladly check it out if not then i will summarise a solution to not make the poor souls who have to read the back and forth messaging ;-;
EDIT: Checked your game and it is bugged is it that your working on it or you haven’t realised
im fixing it rn, its a odd glitch
edit: studio is not responding
Hint: The error is within the pierce function, not sure what it is but it should be there from what i can infer
I know that, the bug is almost fixed
It could be how many parts you made when you pierce through it.
If I were you I would make the pierce effect on the client and who would exploit an effect.
Its 2 parts, how could lag come from that?