Oh well thanks for your help though
Will this work for mobile devices?
Since it uses the peripheral target of the mouse, the object it is hovering over or put on, no. This only works for devices like a PC.
Could you be kind enough to guide me how to make it mobile friendly . . The cursor / tap to shot system from weapons kit game is what I hope to achieve . .
Construct a raycastparams, then set its FilterType
to Enum.RaycastFilterType.Blacklist
and add the character to the FilterDescendantsInstances
.
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Blacklist
params.FilterDescendantsInstances = { player.Character }
...
local result = Workspace:Raycast(origin, direction, params)
My friend hired me to script a gun and I’ll be definitely using this. However, this is only single shot, is there a way to make it automatic?
tool.Activated:Connect(function()
remote:FireServer(cursor.Hit.Position)
end)
Change this to make it so that everytime the mousebutton2 button is held down fire a bullet. This can be done using RunService.Heartbeat (for constant checking) and UserInputService:IsKeyDown() to check if the key is down.
And if it is down then tell the server to fire.
I recommend something like this
local TriggerPulled = false
UserInputService.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.MouseButton1 then
TriggerPulled = true
end)
UserInputService.InputEnded:Connect(function(input)
if input.KeyCode = Enum.KeyCode.MouseButton1 then
TriggerPulled = false
end)
while TriggerPulled == true do
– insert gun shooting mechanics here
How would I make the bullet fly towards where you shot at rather than it being a beam?
Great tutorial also!
How would I get it to update and fire from the shoot part if the character is moving?
Also, is there a way I can add entire teams to this RaycastParams function?
FilterDescendantsInstances is a table so I guess you can just iterate over the team and add their characters to it.
Instead of cloning a gun from ServerStorage you can just use instance.new, but i agree cloning the Part from serverstorage is more useful and easier than using Instance.new
Edit: to answer for the post above me, im not sure but
Bullent_Clone.Size or Bullet_Clone.CFrame might be the cause of it
you should just clone the bullet and use bullet.Velocity = bullet.CFrame.look vector * speed
Because when you shoot backwards the ray just detects your arm or the gun model so it doesnt work but it should work if you shoot in front of you
This tutorial is made really Great! I like this tutorial! . Good job this it reminds me alot of prison life.!
How would I be able to make an automatic gun with this tutorial?
No. Raycasting on the server is completely fine, it isn’t “wasteful”.
Replicating to the client is completely useless and wasteful, you don’t want someone spam shooting the gun and fire loads of remotes to clients causing high network usage.
Also do know that you would be firing remote events to all the players in the game, which is even more wasteful in network usage, considering you will have more than 1 person with the gun.
EDIT:
Also, this tutorial is just for those to get started, not to account for details as incapaz stated.
A single ray has an insignificant impact on the server’s performance. You can usually shoot around 10-50 rays per frame on the server without causing any lag (don’t quote me on this as I’ve only tested this once).
Hey there, would there be any way to add a headshot multiplier to it?