Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Projectile is not working when hitting other players in servers?

Asked by 6 years ago
Edited 6 years ago

I have a projectile that is fired, whenever the projectile is fired it has a script that is cloned into the part the tries to detect whenever it is hit.

Script:

math.randomseed((tick()%1)*1e6) -- to make the damage that it deals more random
local Damage = math.random(25,50)
local damaged = false

script.Parent.Touched:connect(function(hit)
    local Dart = script.Parent
    local plr = game.Players:FindFirstChild(Dart.Name) -- I made the dart named the player's name so I would be able to access the player
    local char = plr.Character
    local hum = char:FindFirstChild("Humanoid") -- Your humanoid

    if damaged then return end
    damaged = true

    local enemyhum = hit.Parent:FindFirstChild("Humanoid") or hit.Parent.Parent:FindFirstChild("Humanoid") -- Humanoid that it is hitting

    if enemyhum  and enemyhum ~= hum then
        Dart.Anchored = true
        enemyhum:TakeDamage(Damage)
        Dart.BodyVelocity:Destroy()
        script:Destroy()
    end

    wait()
    damaged = false
end)

In this Gif I got a pretty good showcase of what happens in servers. It stops but it stops after already hitting it.

https://gyazo.com/1cc11b988b57e8dee9599f3029333827

In the test player this does not happen.

https://gyazo.com/2b756434298a8ab629f1b804498a7b21

Does anyone know a better and more relieable way of detecting when it got hit?

1 answer

Log in to vote
0
Answered by 6 years ago

Server lag is the reason why It already detects hitting but doesn't stop the projectile from server lag. If you want the projectile to return back to its original place set its CFrame.

Ad

Answer this question