I don’t want there to be any lag when shooting from the client, I want the shot to fire instantly
I want that, when reloading the weapon, it’s not possible to shoot from the client without making it easily exploitable, like adding variables on the client, etc…
--[[CLIENT]]--
local replicatedStorage = game:GetService("ReplicatedStorage")
local userInputService = game:GetService("UserInputService")
local hitEvent = replicatedStorage.Events:WaitForChild("HitEvent")
local reloadEvent = replicatedStorage.Events:WaitForChild("ReloadEvent")
userInputService.InputBegan:Connect(function(input, isTyping)
if isTyping then return end
if input.UserInputType == Enum.UserInputType.MouseButton1 then
print("shoot (client)")
hitEvent:FireServer()
end
if input.KeyCode == Enum.KeyCode.R then
print("reload (client)")
reloadEvent:FireServer()
end
end)
--[[SERVER]]--
local replicatedStorage = game:GetService("ReplicatedStorage")
local hitEvent = replicatedStorage.Events:WaitForChild("HitEvent")
local reloadEvent = replicatedStorage.Events:WaitForChild("ReloadEvent")
hitEvent.OnServerEvent:Connect(function(player)
print("shoot (server)")
print("does damage if hit")
end)
reloadEvent.OnServerEvent:Connect(function(player)
task.wait(1.5)
print("reload (server)")
end)
What even is the issue? You say you want this and that, but you don’t tell us what the issue is? It’s clear you’ve substituted some code with print statements, are those statements replaced by actual code in your game? Or have you placed them there as temporary code which you need our help to make?
The thing is, I don’t know how to make a gun like in Phantom Forces, like how they stop shots fired from the client when putting conditionals on the client makes it easily exploitable by hackers
I like to use the roblox FPS template framework.
When you shoot do the raycasting and effects on the client instantly, if an enemy is hit you do the hitmarker and all that.
After that you fire the event and the server does all the sanity checks and then replicates to other clients and fo the damage.
This makes it look way better for the client.
Also as the roblox’s template does I suggest passing a “taggedHumanoid” boolean trough the event. This way the server only needs to do most of the sanity checks when the boolean is true.
As for the no shooting while reloading thing maybe have a table or something for each player to know when theyre reloading (use OOP) and check if they’re reloading. If an exploiter tries shooting while realoding only they will see the visual effects, noone else will be affected.