my bad
pass the part from the client to the server.
Ah directly ? Alright, I will test it then.
But how I do I get the part from the client ?
local plr = game:GetService("Players").LocalPlayer
local mouse = plr:GetMouse()
local isReloading = false
local rs = game:GetService("ReplicatedStorage")
local pressing = false
local ColorAmmo = script.ColorAmmo
local DamageAmmo = script.DamageAmmo
local function CreateBullet(nameGun, pos, dmg, col, origplr)
local char = origplr.Character
local gun = char:FindFirstChild(nameGun)
local cp = gun:FindFirstChild("ShootPos").CFrame.p
local ray = Ray.new(cp, (pos - cp).unit * 300)
local part, position = workspace:FindPartOnRay(ray, char, false, true)
local beam = Instance.new("Part", workspace)
beam.BrickColor = col
beam.FormFactor = "Custom"
beam.Material = Enum.Material.Neon
beam.Transparency = 0.8
beam.Anchored = true
beam.Locked = true
beam.CanCollide = false
local distance = (gun:FindFirstChild("ShootPos").CFrame.p - position).magnitude
beam.Size = Vector3.new(0.04, 0.04, distance)
beam.CFrame = CFrame.new(cp, position) * CFrame.new(0, 0, -distance / 2)
game:GetService("Debris"):AddItem(beam, 0.1)
end
local function handleAction()
pressing = true
local char = plr.Character
local possibleARI = char:FindFirstChild("ARI")
while true do
local isEquipped = rs.Events.Items.GetARIEquipped:InvokeServer()
if isEquipped then
if not isReloading then
if pressing then
rs.Events.Items.ARIShoot:FireServer(pressing) -- Animation
rs.Events.Items.Shoot:FireServer("ARI", mouse.Hit.p, DamageAmmo.Value, ColorAmmo.Value, part)
CreateBullet("ARI", mouse.Hit.p, DamageAmmo.Value, ColorAmmo.Value, plr)
task.wait(0.1)
end
end
end
end
end
rs.Events.Items.Shoot.OnClientEvent:Connect(function(rename, repos, redmg, reammo, replr)
CreateBullet(rename, repos, redmg, reammo, replr)
end)
mouse.Button1Down:Connect(handleAction)
mouse.Button1Up:Connect(function()
pressing = false
end)
I moved the call of the event Shoot.
local plr = game:GetService("Players").LocalPlayer
local mouse = plr:GetMouse()
local isReloading = false
local rs = game:GetService("ReplicatedStorage")
local pressing = false
local ColorAmmo = script.ColorAmmo
local DamageAmmo = script.DamageAmmo
local function CreateBullet(nameGun, pos, dmg, col, origplr)
local char = origplr.Character
local gun = char:FindFirstChild(nameGun)
local cp = gun:FindFirstChild("ShootPos").CFrame.p
local ray = Ray.new(cp, (pos - cp).unit * 300)
local part, position = workspace:FindPartOnRay(ray, char, false, true)
local beam = Instance.new("Part", workspace)
beam.BrickColor = col
beam.FormFactor = "Custom"
beam.Material = Enum.Material.Neon
beam.Transparency = 0.8
beam.Anchored = true
beam.Locked = true
beam.CanCollide = false
local distance = (gun:FindFirstChild("ShootPos").CFrame.p - position).magnitude
beam.Size = Vector3.new(0.04, 0.04, distance)
beam.CFrame = CFrame.new(cp, position) * CFrame.new(0, 0, -distance / 2)
rs.Events.Items.Shoot:FireServer("ARI", mouse.Hit.p, DamageAmmo.Value, ColorAmmo.Value, part)
game:GetService("Debris"):AddItem(beam, 0.1)
end
local function handleAction()
pressing = true
local char = plr.Character
local possibleARI = char:FindFirstChild("ARI")
while true do
local isEquipped = rs.Events.Items.GetARIEquipped:InvokeServer()
if isEquipped then
if not isReloading then
if pressing then
rs.Events.Items.ARIShoot:FireServer(pressing) -- Animation
CreateBullet("ARI", mouse.Hit.p, DamageAmmo.Value, ColorAmmo.Value, plr)
task.wait(0.1)
end
end
end
end
end
rs.Events.Items.Shoot.OnClientEvent:Connect(function(rename, repos, redmg, reammo, replr)
CreateBullet(rename, repos, redmg, reammo, replr)
end)
mouse.Button1Down:Connect(handleAction)
mouse.Button1Up:Connect(function()
pressing = false
end)
1 Like
Thank you ! It works now, have a nice day :>.
1 Like
By the way I have still a problem there is still a “latence” between my movement and the beam.