#pls help me

1 messages · Page 1 of 1 (latest)

magic wyvern
#

I need help with my shooting system. When I shoot, I have to aim ahead of the user to hit them. If I shoot directly at them, it doesn't register. Also, when they are standing still and I place the cursor outside the dummy, the bullets still count as hitting

autumn cliffBOT
#

studio** You are now Level 2! **studio

magic wyvern
delicate egret
#

bad image but this is what im saying

#

so for example if there is a wall in front of the gun, even though the player's crosshair isnt blocked, the gun's bullet will still be blocked

#

tldr instead of doing:

workspace:Raycast(Glock.Handle.Position, direction, Raycastparams)

make the start position of the raycast the player's camera position

magic wyvern
#

🤔

broken creek
#

the issues is , Ray starts from Glock.Handle.Position but you're aiming from camera

also there is no lag compensation for moving targets

Ray direction calculation doesnt account for the offset

#
Events.Fire.OnServerEvent:Connect(function(Player, Mousepos)
    local character = Player.Character
    if not character then return end
    
    local head = character:FindFirstChild("Head")
    if not head then return end
    
    -- here is the trick
    local rayOrigin = head.Position
    
    local Raycastparams = RaycastParams.new()
    Raycastparams.FilterDescendantsInstances = {Player.Character}
    Raycastparams.FilterType = Enum.RaycastFilterType.Blacklist
    
    local direction = (Mousepos - rayOrigin).Unit * 500
    local RaycastResults = workspace:Raycast(rayOrigin, direction, Raycastparams)
    
    --what ever your code down there , keeps the same
end)
#

also a better thing to do is , send both camera position and target
update the client script firing line

Resources.Events.Fired:FireServer(Mouse.Hit.Position, Camera.CFrame.Position)

for server script

Events.Fire.OnServerEvent:Connect(function(Player, TargetPos, CameraPos)
    local Raycastparams = RaycastParams.new()
    Raycastparams.FilterDescendantsInstances = {Player.Character}
    Raycastparams.FilterType = Enum.RaycastFilterType.Blacklist
    
    local direction = (TargetPos - CameraPos).Unit * 500
    local RaycastResults = workspace:Raycast(CameraPos, direction, Raycastparams)
    
    local Sound = Glock.Handle.FireSound:Clone()
    Sound.Parent = workspace.Gun
    Sound:Play()
    game.Debris:AddItem(Sound, 5)
    
    -- whatever left from your script
end)

add this in server script for lag compensation with moving targets

local function predictPosition(targetPart, bulletSpeed, distance)
    local velocity = targetPart.Velocity
    local timeToHit = distance / bulletSpeed
    return targetPart.Position + (velocity * timeToHit)
end
magic wyvern
#

Can u help me fix it? I’ll give u 200 robux crying

#

How much would u charge to fix my shoot system so bullets hit right? Also my ragdoll sometimes works but other times parts separate

broken creek
#

damn thats too many issues

#

for the headshots issue

The problem is youre only checking for parts named "Head" but accessories block the raycast

if RaycastResults then
    local HitPart = RaycastResults.Instance
    local character = nil
    local humanoid = nil
   
    local current = HitPart
    while current and current ~= workspace do
        humanoid = current:FindFirstChildOfClass("Humanoid")
        if humanoid then
            character = current
            break
        end
        current = current.Parent
    end
    
    if character and humanoid then
        local isHeadshot = false
        if HitPart.Name == "Head" then
            isHeadshot = true
        elseif HitPart.Parent == character and HitPart:FindFirstChild("AccessoryWeld") then
            local weld = HitPart:FindFirstChild("AccessoryWeld")
            if weld and weld.Part1 and weld.Part1.Name == "Head" then
                isHeadshot = true
            end
        end
        
        if isHeadshot then
            humanoid:TakeDamage(100)
            local Sound = Glock.Resources.SpecialSounds.BigBloodDamage:Clone()
            Sound.Parent = character
            Sound:Play()
        else
            humanoid:TakeDamage(18)
            local Sound = Glock.Resources.SpecialSounds.BodyBlood:Clone()
            Sound.Parent = character
            Sound:Play()
            
            local Blood = BloodSpark:Clone()
            Blood.Parent = RaycastResults.Instance
            Blood.Position = RaycastResults.Position
            Blood.CFrame = CFrame.new(Blood.Position, Blood.Position + RaycastResults.Normal)
            game.Debris:AddItem(Blood, 0.40)
        end
    end
end

replace your headshot/body shot detection with this

#

replace this in the client script

Resources.Events.Fired:FireServer(Mouse.Hit.Position, Camera.CFrame.Position)
#

update the server script with

Events.Fire.OnServerEvent:Connect(function(Player, TargetPos, CameraPos)
    local Raycastparams = RaycastParams.new()
    Raycastparams.FilterDescendantsInstances = {Player.Character}
    Raycastparams.FilterType = Enum.RaycastFilterType.Blacklist
    
    local direction = (TargetPos - CameraPos).Unit * 1000
    local RaycastResults = workspace:Raycast(CameraPos, direction, Raycastparams)
    
    local Sound = Glock.Handle.FireSound:Clone()
    Sound.Parent = workspace.Gun
    Sound:Play()
    game.Debris:AddItem(Sound, 5)
    
    Glock.Slider.Attachment.Flash.Enabled = true
    task.wait(0.1)
    Glock.Slider.Attachment.Flash.Enabled = false
    Glock.Slider.Attachment.Smoke.Enabled = true
    
    -- your hit detection code here (with the improved version above)
    
    task.wait(0.30)
    Glock.Slider.Attachment.Smoke.Enabled = false
end)
#

for ragdoll use this

local function createRagdoll(character)
    for _, joint in pairs(character:GetDescendants()) do
        if joint:IsA("Motor6D") then
            local weld = Instance.new("WeldConstraint")
            weld.Part0 = joint.Part0
            weld.Part1 = joint.Part1
            weld.Parent = joint.Parent
            joint:Destroy()
        end
    end
end

( where ever your ragdoll script system is )

#

i guess this will fix all your issues

magic wyvern
#

client : --[[
¦¦¦¦¦+ ¦¦¦¦¦¦+ ¦¦+ ¦¦+ ¦¦¦¦¦+ ¦¦¦¦¦¦+ ¦¦¦¦¦¦+ ¦¦¦¦¦¦¦+¦¦¦¦¦¦¦¦+¦¦+ ¦¦+¦¦¦¦¦¦+ ¦¦+ ¦¦¦¦¦¦+
¦¦+--¦¦+¦¦+----+ ¦¦¦ ¦¦¦¦¦+--¦¦+¦¦+--¦¦+¦¦+---¦¦+ ¦¦+----++--¦¦+--+¦¦¦ ¦¦¦¦¦+--¦¦+¦¦¦¦¦+---¦¦+
¦¦¦¦¦¦¦¦¦¦¦ ¦¦¦+¦¦¦ ¦¦¦¦¦¦¦¦¦¦¦¦¦¦ ¦¦¦¦¦¦ ¦¦¦ ¦¦¦¦¦¦¦+ ¦¦¦ ¦¦¦ ¦¦¦¦¦¦¦¦¦++¦¦¦¦¦¦ ¦¦¦
¦¦+--¦¦¦¦¦¦ ¦¦¦¦¦¦ ¦¦¦¦¦+--¦¦¦¦¦¦ ¦¦¦¦¦¦ ¦¦¦ +----¦¦¦ ¦¦¦ ¦¦¦ ¦¦¦¦¦+--¦¦+¦¦¦¦¦¦ ¦¦¦
¦¦¦ ¦¦¦+¦¦¦¦¦¦+++¦¦¦¦¦¦++¦¦¦ ¦¦¦¦¦¦¦¦¦+++¦¦¦¦¦¦++ ¦¦¦¦¦¦¦¦ ¦¦¦ +¦¦¦¦¦¦++¦¦¦ ¦¦¦¦¦¦+¦¦¦¦¦¦++
+-+ +-+ +-----+ +-----+ +-+ +-++-----+ +-----+ +------+ +-+ +-----+ +-+ +-++-+ +-----+
]]

--[[
© 2025 AGUADO STUDIO - Todos los derechos reservados
Scripting avanzado para experiencias profesionales
]]

repeat wait() until script.Parent.Parent.Parent:IsA("Player")
repeat wait() until script.Parent.Parent.Parent.Character:FindFirstChild("Humanoid")

local player = game.Players.LocalPlayer
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")

local variables = script.Parent:WaitForChild("variables")
local variables_ragdoll = variables:WaitForChild("ragdoll")
local variables_ragdollonclient = variables:WaitForChild("ragdollonclient")

local events = script.Parent:WaitForChild("events")
local events_variableserver = events:WaitForChild("variableserver")
local events_resetclient = events:WaitForChild("resetclient")

local functions = script.Parent:WaitForChild("functions")
local functions_remoteragdoll = functions:WaitForChild("remoteragdoll")
local functions_remoteragdollvelocity = functions:WaitForChild("remoteragdollvelocity")

function killRagdoll(inst)
if string.match(inst.Name,"'s Ragdoll") then
local hum = inst:WaitForChild("Humanoid")
hum.Health = 1
hum.Health = 0
end
end

for _,v in pairs(workspace:GetChildren()) do
killRagdoll(v)
end

workspace.ChildAdded:Connect(function(child)
killRagdoll(child)
end)

function enableRagdoll()
humanoid:ChangeState(Enum.HumanoidStateType.Physics)
humanoid.AutoRotate = false
pcall(function() character.Animate.Disabled = true end)
for _,v in pairs(humanoid:GetPlayingAnimationTracks()) do
if v.Name ~= "DummyAnim" and v.Animation.AnimationId ~= "rbxassetid://0" then
v:Stop(0)
end
end
variables_ragdollonclient.Value = true
end

function disableRagdoll()
humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
humanoid.AutoRotate = true
pcall(function() character.Animate.Disabled = false end)
variables_ragdollonclient.Value = false
for _,v in pairs(character:GetChildren()) do
if v:IsA("BasePart") then
v.Velocity = Vector3.new(0,0,0)
v.RotVelocity = Vector3.new(0,0,0)
end
end
end

function functions_remoteragdoll.OnClientInvoke(mode, velocity)
if mode then
enableRagdoll()
if velocity then
character.HumanoidRootPart.Velocity = velocity
end

    -- Esperar segundos aleatorios antes de levantarse
    local waitTime = math.random(2, 5)
    task.delay(waitTime, function()
        if humanoid.Health > 0 then
            disableRagdoll()
        end
    end)
else
    disableRagdoll()
end

end

function functions_remoteragdollvelocity.OnClientInvoke(velocity)
character.HumanoidRootPart.Velocity = velocity
end

-- Activar ragdoll automáticamente al morir
humanoid.Died:Connect(function()
variables_ragdoll.Value = true
events_variableserver:FireServer("ragdoll", true)

-- Quitar vida aleatoria al morir
local damage = math.random(5, 20)  -- Quitar vida aleatoria
humanoid:TakeDamage(damage)

end)

-- Refrescar ragdoll desde servidor
script.Parent.events.variableserver.OnClientEvent:Connect(function()
events_variableserver:FireServer("ragdoll", variables_ragdoll.Value)
end)

#

and ty for helping me

magic wyvern
#

@broken creek

broken creek
#

for the delays

reduce the network latency

-- in server script, add position prediction
Events.Fire.OnServerEvent:Connect(function(Player, TargetPos, CameraPos, Timestamp)
    local serverTime = tick()
    local latency = serverTime - Timestamp
    
    local predictedPos = TargetPos + (targetVelocity * latency)
    
    local direction = (predictedPos - CameraPos).Unit * 1000
    local RaycastResults = workspace:Raycast(CameraPos, direction, Raycastparams)
    -- your code down here
end)
-- in client script
Resources.Events.Fired:FireServer(Mouse.Hit.Position, Camera.CFrame.Position, tick())
Raycastparams.FilterDescendantsInstances = {Player.Character, workspace.Effects}
Raycastparams.FilterType = Enum.RaycastFilterType.Blacklist
Raycastparams.IgnoreWater = true

all those should solve your delay issues