local Debris = game:GetService("Debris")
local barrel = script.Parent:WaitForChild("Barrel")
local player = game.Players.LocalPlayer
local char = player.Character
local damage = 35
script.Parent.Equipped:Connect(function(mouse)
mouse.Button1Down:Connect(function()
local char = player.Character
local barrel = char.laser.Barrel
local laser = Ray.new(barrel.CFrame.p,(mouse.Hit.p - barrel.CFrame.p).unit * 500)
local hitpart, hitpos = game.Workspace:FindPartOnRay(laser, char, false, true)
local laserbeam = Instance.new("Part",workspace)
laserbeam.Material = Enum.Material.Neon
laserbeam.Anchored = true
laserbeam.CanCollide = false
local distance = (barrel.CFrame.p - hitpos).Magnitude
laserbeam.Size = Vector3.new(0.4, 0.4, distance)
Debris:AddItem(laserbeam, .1)
laserbeam.CFrame = CFrame.new(barrel.CFrame.p,hitpos) * CFrame.new(0,0, -distance/2)
if hitpart then
local humanoid = hitpart.Parent:WaitForChild("Humanoid")
if humanoid then
if humanoid.Parent.Name ~= player.Name then
humanoid:TakeDamage(35)
end
end
end
Debris:AddItem(laserbeam,0.1)
end)
end)
I want to make how can I show everyone the part(laserbeam) without using remotevent? i know its possible but i don’t know how to do
Sadly, a consequence of remotes is the delay between the server and the client. You can try to mitigate this by making the server render the bullet from the gun barrel’s position instead of the player sending the starter position.
I really hope you’re not doing the gun logic this way due to exploiting risks.
I’m assuming you have the player send the starting position to the server, where it renders the bullet and stuff. Instead, have the player only send the ending position, and have the server position the bullet from the end of the barrel.
-- player is obtained from a remote
local plrobj = player.Character
local guntool = plrobj:FindFirstChildWhichIsA("Tool")
local gun = guntool.gunmodel
local barrel = gun.Parts.BarrelEnd.position --the bullet is rendered from this
This is how my game is ordered, and yours might be very different.
I’m trying to say that in your server script, instead of getting the position from the remote that a player sends, get it directly from the player’s gun model.