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

What is the best way to handle raycasting for a gun tool?

Asked by 4 years ago

What is the best way to handle raycasting for guns so remote events aren't spammed and raycast is visible to everyone? The chunk of code I have made regarding firing the gun is below. Please read bottom of post before answering!

Vulcan.Equipped:Connect(function(mouse) -- Equipping Vulcan (Hold animation)
    UserInputService.InputBegan:Connect(function(ShootKey)
        if ShootKey.UserInputType == Enum.UserInputType.MouseButton1 then
            GunFire:FireServer(true)
        end
    end)
    UserInputService.InputEnded:Connect(function(StopShootKey)
        if StopShootKey.UserInputType == Enum.UserInputType.MouseButton1 then
            GunFire:FireServer(false)
        end
    end)

    ConnectM6D:FireServer(Vulcan.BodyAttach)
    char["Right Arm"].GunMotor6D.Part0 = char["Right Arm"]
    char["Right Arm"].GunMotor6D.Part1 = Vulcan.BodyAttach
    HoldTrack:Play()
end)

Above is my current code in localscript. Below is my server script.

VulcanEvent:WaitForChild("GunFire").OnServerEvent:Connect(function(plr, CanFire)
    print(CanFire)
end)

Neither gives an error and both are doing what they should. This would work fine for singleplayer, but in multiplayer, everyone hold-clicking will be able to fire the event therefore messing up the trues and falses for everyone. How would you handle raycasts for a gun while keeping remote event spamming to a minimum and with minimal chances of messing up the true/false for each player? For context, this is for a gun clan fort and most likely, everyone in the server will be using said guns most of the time. Apologies if my explanations are unclear, let me know if I don't make sense and I'll rephrase.

1 answer

Log in to vote
1
Answered by 4 years ago

Read this article.

0
Apologies if I'm mistaken, but isn't it not FE? I have looked there before posting and it seems like the entire thing is in a localscript with no remote events...will rays replicate to server if I follow said article? AthenaThorn 4 — 4y
0
No, you'll need to make a remote event for casting the ray. youtubemasterWOW 2741 — 4y
Ad

Answer this question