Hi i'm Having a BIG problem with my First RemoteEvent Tool, and when i say FIRST i mean.. Works fine, but i could do better and increase Performance
uuh.. sorry if my coding seems confusing... (the reason why i need help) also i'm asking for help because i just CAN'T FIND OUT HOW TO DECREASE THE LAG!
Local Script:
wait()
local Tool = script.Parent
Player = game.Players.LocalPlayer
mouse = Player:GetMouse()
char = Player.Character
repeat wait() until Player.Character
hum = char.Humanoid
repeat wait() until char.Humanoid
local en = true
Tool.Activated:connect(function()
if not en then return end
local point = mouse.Hit.p
en = false
Tool.FireBlast:FireServer(point)
en = true
end)
Script:
local Tool = script.Parent
local Object = game:GetService('ServerStorage'):WaitForChild("Blast_Model")
local R6RightAnim = Tool.R6Content.RightBlast
local R6LeftAnim = Tool.R6Content.LeftBlast
local R15RightAnim = Tool.R15Content.RightBlast
local R15LeftAnim = Tool.R15Content.LeftBlast
local Enabled = true
local Cooldown = 0.01 --//Trust me you don't wanna put this to 0 if people use auto clicker, Default is [0.01]
local Blast_Speed = 100
local Damage = 5
wait(.2) --//Don't Change
function NewBlast(Damage,Speed,Target,StartPos,pName)
local Blast = Object:Clone()
Blast:WaitForChild('Damage').Value = Damage
Blast.Parent = workspace
Blast.CFrame = StartPos
game.Debris:AddItem(Blast,5)
Blast.Velocity = ((Target - Blast.Position).unit) * Speed
local force = Instance.new'BodyForce'
force.force = Vector3.new(0, Blast:GetMass()*workspace.Gravity, 0)
force.Parent = Blast
local BlastColor = ColorSequence.new(Blast.Color)
Blast.Trail.Color = BlastColor
Blast:WaitForChild('Owner').Value = pName
Blast:WaitForChild('Damage').Value = Damage
Blast:WaitForChild('GeneralScript').Disabled = false
end
function PlayAnimation(hum, anim)
local Animation = hum:LoadAnimation(anim)
Animation:Play()
end
function CreateSound(audioID,audioVolume,pitch,debris,paren)
local link = 'rbxassetid://'
local Audio = Instance.new('Sound')
Audio.SoundId = link..audioID
Audio.Volume = audioVolume
Audio.PlaybackSpeed = pitch
Audio.Parent = paren
Audio.Name = math.random(1, 1000000) --//Names the Audio Randomly a Number from 1 to 1000000
Audio.EmitterSize = 3.5
game.Debris:AddItem(Audio,debris)
Audio:Play()
end
Tool.FireBlast.OnServerEvent:connect(function(Player,p)
local humanoid = Player.Character:WaitForChild('Humanoid')
if humanoid and Enabled == true then
Enabled = false
if (humanoid.RigType == Enum.HumanoidRigType.R6) then
local RandomPart = math.random(1,2)
if RandomPart == 1 then wait(.1)
NewBlast(10,125,p,CFrame.new(Player.Character['Right Arm'].RightGripAttachment.WorldPosition.X,Player.Character['Right Arm'].RightGripAttachment.WorldPosition.Y,Player.Character['Right Arm'].RightGripAttachment.WorldPosition.Z),Player.Name)
PlayAnimation(humanoid, R6RightAnim)
CreateSound(145681580,.3,1.1,0.8,Player.Character.Torso)
CreateSound(853857055,.5,1,1,Player.Character.Torso)
else wait(.1)
NewBlast(10,125,p,CFrame.new(Player.Character['Left Arm'].LeftGripAttachment.WorldPosition.X,Player.Character['Left Arm'].LeftGripAttachment.WorldPosition.Y,Player.Character['Left Arm'].LeftGripAttachment.WorldPosition.Z),Player.Name)
PlayAnimation(humanoid, R6LeftAnim)
CreateSound(145681580,.3,1.1,0.8,Player.Character.Torso)
CreateSound(853857055,.5,1,1,Player.Character.Torso)
end
end
if (humanoid.RigType == Enum.HumanoidRigType.R15) then
local RandomPart = math.random(1,2)
if RandomPart == 1 then wait(.1)
NewBlast(10,125,p,CFrame.new(Player.Character['RightHand'].RightGripAttachment.WorldPosition.X,Player.Character['RightHand'].RightGripAttachment.WorldPosition.Y,Player.Character['RightHand'].RightGripAttachment.WorldPosition.Z),Player.Name)
PlayAnimation(humanoid, R15RightAnim)
CreateSound(145681580,.3,1.1,0.8,Player.Character.UpperTorso)
CreateSound(853857055,.5,1,1,Player.Character.UpperTorso)
else wait(.1)
NewBlast(10,125,p,CFrame.new(Player.Character['LeftHand'].LeftGripAttachment.WorldPosition.X,Player.Character['LeftHand'].LeftGripAttachment.WorldPosition.Y,Player.Character['LeftHand'].LeftGripAttachment.WorldPosition.Z),Player.Name)
PlayAnimation(humanoid, R15LeftAnim)
CreateSound(145681580,.3,1.1,0.8,Player.Character.UpperTorso)
CreateSound(853857055,.5,1,1,Player.Character.UpperTorso)
end
end
end
wait(Cooldown)
Enabled = true
end)
This is a Free model so you can take it:
"What to do now?" Change/Remove/Edit some lines there if that will help to remove the LAG
Hey uh.. RemoteEvents should be placed at ReplicatedStorage... uh.. ReplicatedFirst?... or it doesn't matter if it has been placed inside the Tool?
*Important: My Network isn't bad, i can prove it, when i tested it in the first time the delay was from 1 to 3 seconds. so i had a very good idea, why not take a free model tool wich uses RemoteEvent and compare the delay? the free model had a Delay of 0.1 to 0.2 Seconds. so the problem isn't in my Network, the problem is in my Scripting.
and i'm not requesting a script from anyone, i just want some help to figure out how to properly use RemoteEvents.

2 comments
I mean you have the potential to be cloning an entire model every 0.01 seconds, of course that will lag. You need to find a clever way to give the effect you want without literally cloning something every 0.01 seconds.
Answering another one of your questions, people usually put RemoteEvents/RemoteFunctions in the ReplicatedStorage since both Client and Server can access it.