I have been trying to make the pettel scatter viewable for all players, and for some reason
I can’t seem to do it for the server but I can do it for the client.
I have tried so many things, but it either will break the raycasting, or not show up at all.
Here are my scripts:
Mouse.Button1Down:connect(function()
if Equipped == true and ReloadEnabled == false and FireEnabled == true and SingleShot == true then
if Clip.Value > 0 then
FireEnabled = false
Clip.Value = Clip.Value - 1
game.ReplicatedStorage.GunFE.SoundPlay:FireServer(GunShot)
localBullet()
local Raycast = Ray.new(Tool.BPoint.CFrame.p, (PMouse.Hit.p - Tool.BPoint.CFrame.p).unit * BulletDistance)
local Part, Position = game.Workspace:FindPartOnRay(Raycast, Player.Character, false, true)
local Distance = (Tool.BPoint.CFrame.p - Position).magnitude
game.ReplicatedStorage.GunFE.Shoot:FireServer(Raycast, MuzzleL, Part, Position, Distance, Tool.BPoint.CFrame.p, Damage, ShellEject, MuzzleF, Tool, script.ServerBullet)
GuiUpdate()
wait(TimeBetweenShots)
FireEnabled = true
elseif Clip.Value <= 0 then
game.ReplicatedStorage.GunFE.SoundPlay:FireServer(EmptyClip)
Reload()
end
end~~~
-- The script below is the client script
function localBullet()
for i = 1,7 do
local RNDM = Random.new()
local maximumOffset = 2
local pelletSpread = Vector3.new(RNDM:NextNumber(-maximumOffset, maximumOffset), RNDM:NextNumber(-maximumOffset, maximumOffset), RNDM:NextNumber(-maximumOffset, maximumOffset))
local Raycast = Ray.new(Tool.BPoint.CFrame.p, (PMouse.Hit.p - Tool.BPoint.CFrame.p + pelletSpread).unit * BulletDistance)
local Part, Position = game.Workspace:FindPartOnRay(Raycast, Player.Character, false, true)
local Distance = (Tool.BPoint.CFrame.p - Position).magnitude
local Bullet = Instance.new("Part", game.Workspace)
game:GetService('Debris'):AddItem(Bullet, 0.05)
Bullet.Size = Vector3.new(0.2, 0.2, Distance)
Bullet.BrickColor = BrickColor.new("New Yeller")
Bullet.Parent = Tool.BPoint
Bullet.Anchored = true
Bullet.CanCollide = false
Bullet.Material = Enum.Material.Neon
Bullet.Transparency = 0.4
Bullet.CFrame = CFrame.new(Tool.BPoint.CFrame.p, Position) * CFrame.new(0, 0, -Distance / 2)
end
What if you fired a remote event to the server, and the server fired a remote event to all clients to make the shotgun blast locally? In order to deal with the overlap on the client that fired the gun, you could check if the shotgun blast came from itself.
First of all there some things that can be changed , use UserInputService for detecting Mouse Click and use the new method of raycast that is workspace:Raycast(Origin,Direction,Params).
When you click fire a remote event to the server Cast the Ray there , do the damage and stuffs etc. Then fire a remote event to all the clients and do the Visual of the Raycast on the client.
EDIT: Hit detection can be done on the client , then verify it in the server.
I think I could make it work with the current script(s) & I think I am just overcomplicating this. One ray is able to appear on the Server from something like this:
game.ReplicatedStorage.GunFE.Shoot.OnServerEvent:connect(function(Player, Raycast)
(script goes here)
end
It works perfectly for guns that don’t have multiple rays, and maybe the issue would be to somehow include RNDM, maxoffset, pelletspread into the event. I have tried numerous things.
I would not suggest doing it in the server , doing it the client would be much smoother and do not need to calculate physics on the server. When I mean client , I mean every client.
I have already mentioned this in my first post : "When you click, fire a remote event to the server then Cast the Ray there , do the damage and stuffs etc. Then fire a remote event to all the clients and do the Visual of the Raycast on the client.
EDIT: Hit detection can be done on the client , then verify it in the server."