Have you heard about RemoteEvent client/server transportation? I believe it can help you
Basically, just send the Mouse’s Hit Position to the server and handle the bullet & bullet’s Velocity from there (Unless if you wanna handle the hit detection on the server that is)
Then you can handle the majority of your LocalScript on your local side to the server (Creating the Part from the server side, using the Velocity from your passed variable, etc)
After a long time making scripts, i’m still struggling to make it, based on that i made these scripts:
Local
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local LocalPlayerGetMouse = LocalPlayer:GetMouse()
local Mouse = LocalPlayerGetMouse.Hit.p
local PartVelocity = 300
local cooldown = false
local Number = 1
script.Parent.Activated:Connect(function()
if cooldown == false then
cooldown = true
game.ReplicatedStorage.Events.arma:FireServer(PartVelocity, Mouse, Number)
end
end)
Server
game.ReplicatedStorage.Events.arma.OnServerEvent:Connect(function(plr, PartVelocity, Mouse, Number)
local folder = workspace.Tiros
local Part = Instance.new("Part")
Part.Name = "Part" .. Number
Part.CanCollide = false
Part.Material = Enum.Material.Neon
Part.BrickColor = BrickColor.new("Lime green")
Part.Size = Vector3.new(0.5,0.5,0.5)
game.ReplicatedStorage.GunValue:Clone().Parent = Part
Part.CFrame = plr.Character.RightHand.CFrame
Part.Velocity = CFrame.new(plr.Character.Head.CFrame.p, Mouse).lookVector * PartVelocity
Number += 1
Part.Parent = folder
end)
You’re only getting the Mouse’s Position once and that’s it, when instead you should be getting the Position time you fire the Event so
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local LocalPlayerGetMouse = LocalPlayer:GetMouse()
local PartVelocity = 300
local cooldown = false
local Number = 1
script.Parent.Activated:Connect(function()
if cooldown == false then
cooldown = true
local Mouse = LocalPlayerGetMouse.Hit.p
game.ReplicatedStorage.Events.arma:FireServer(PartVelocity, Mouse, Number)
end
end)