-
What do you want to achieve? Keep it simple and clear!
Bullets that can be fired from the client then authenticated on the server before damage (the raycast on the serverside authenticates)
-
What is the issue? Include screenshots / videos if possible!
My hitreg still won’t work or deal damage, the debug prints “unshootable” won’t work.
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I’ve filled it with debug prints I can specifically test for and none of the serverside prints are showing up. Shooting non-players gives an error but that’s not what I’m looking for. I have no error AND no functionality when shooting a limb. The game IS R6.
Client Code:
local players = game:GetService("Players")
local replicatedstorage = game:GetService("ReplicatedStorage")
local plr = players.LocalPlayer
local mouse = plr:GetMouse()
local tool = script.Parent
local remote = replicatedstorage.GunRemote
local visualsfolder = game.Workspace["Bullet Impacts"]
local tdebounce = false
local debtime = tool:GetAttribute("Cooldown")
mouse.TargetFilter = visualsfolder
mouse.TargetFilter = tool
mouse.TargetFilter = game.Players.LocalPlayer.Character
tool.Activated:Connect(function()
if not tdebounce then
tdebounce = true
task.spawn(function()
task.wait(debtime)
tdebounce = false
end)
local startPosition = tool.Start.Position
local endposition = mouse.Hit.Position
local maxr = tool:GetAttribute("MaxRange")
--reg
local direction = (endposition-startPosition).Unit * maxr
--legitimacychecks
if (startPosition-tool.Start.Position).Magnitude>10 then
plr:Kick("Bullets cannot be legitimized. Please fix your internet connection and then rejoin.")
end
local raycast = game.Workspace:Raycast(startPosition,direction)
if raycast then
--hitregchecker.Transparency = 1
print(raycast.Instance.Name)
local hitCharacter = raycast.Instance.Parent
local humanoid = hitCharacter:FindFirstChild("Humanoid")
if humanoid then
elseif raycast.Instance.Name=="Left Arm" then
remote:FireServer("Left Arm", hitCharacter, tool)
print("hit validated")
elseif raycast.Instance.Name == "Right Arm" then
remote:FireServer("Right Arm", hitCharacter, tool)
print("hit validated")
elseif raycast.Instance.Name == "Left Leg" then
remote:FireServer("Left Leg", hitCharacter, tool)
print("hit validated")
elseif raycast.Instance.Name == "Right Leg" then
remote:FireServer("Right Leg", hitCharacter, tool)
print("hit validated")
elseif raycast.Instance.Name=="HumanoidRootPart" or raycast.Instance.Name == "Torso" then
remote:FireServer("HumanoidRootPart", hitCharacter, tool)
print("hit validated")
elseif raycast.Instance.Name== "Head" then
remote:FireServer("Head", hitCharacter, tool)
print("hit validated")
else
remote:FireServer("Head", hitCharacter, tool)
print("hit validated")
end
end
end
end)
Server Code:
local replicatedstorage = game:GetService("ReplicatedStorage")
local remoteEvent = replicatedstorage.GunRemote
remoteEvent.OnServerEvent:Connect(function(plr, bodypart, target, tool)
local maxr = tool:GetAttribute("MaxRange")
local startPosition = tool.Start.Position
if target:IsA("Accessory") then
target = target.Parent
bodypart = "Head"
end
local endPosition = target[bodypart].Position
local unshootable = false
--reg
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {tool,plr.Character}
raycastParams.FilterType = Enum.RaycastFilterType.Exclude
raycastParams.IgnoreWater = true
local direction = (endPosition-startPosition).Unit * maxr
local raycast = game.Workspace:Raycast(startPosition,direction,raycastParams)
if raycast.Instance.Name == bodypart then
print("Shootable")
else
unshootable = true
print("unshootable")
end
if unshootable == false then
if bodypart == "Left Leg" then
print(tostring(tool:GetAttribute("LegDamage")))
target.Humanoid.Health -= tool:GetAttribute("LegDamage")
task.spawn(function()
target.Values.DefaultWalkSpeed.Value = 12
wait(2)
target.Values.DefaultWalkSpeed.Value = 16
end)
elseif bodypart == "Right Leg" then
target.Humanoid.Health -= tool:GetAttribute("LegDamage")
task.spawn(function()
target.Values.DefaultWalkSpeed.Value = 12
wait(2)
target.Values.DefaultWalkSpeed.Value = 16
end)
elseif bodypart == "Right Arm" then
target.Humanoid.Health -= tool:GetAttribute("ArmDamage")
elseif bodypart == "Left Arm" then
target.Humanoid.Health -= tool:GetAttribute("ArmDamage")
elseif bodypart == "Torso" then
target.Humanoid.Health -= tool:GetAttribute("TorsoDamage")
elseif bodypart == "HumanoidRootPart" then
target.Humanoid.Health -= tool:GetAttribute("TorsoDamage")
elseif bodypart == "Head" then
target.Humanoid.Health -= tool:GetAttribute("HeadDamage")
end
--legitimacychecks
local raycast = game.Workspace:Raycast(startPosition,direction)
if raycast then
print(raycast.Instance.Name)
local hitCharacter = raycast.Instance.Parent
local humanoid = hitCharacter:FindFirstChild("Humanoid")
end
end
end)