Super Simple Gun Tutorial in Roblox Studio

Опубликовано: 16 Май 2026
на канале: PR0_DEVV
7,899
327

In this video I show you how to make a super simple gun in roblox studio, which uses raycasting to create a hitscan effect.
Even though most games on roblox use more advanced gun systems, I think there's something beautiful about a raycasting tool.

SCRIPTS:

GunServer:

local tool = script.Parent
local handle = tool:WaitForChild("Handle")
local fire_point = handle:WaitForChild("FirePoint")

local remote_event = tool:WaitForChild("FireGun")

local function visualise(A, B)
local distance = (B-A).Magnitude

local visual = Instance.new("Part")
visual.BrickColor = BrickColor.new("Yellow flip/flop")
visual.Material = Enum.Material.Neon
visual.Transparency = 0.2
visual.Anchored = true
visual.CanCollide, visual.CanTouch, visual.CanQuery, visual.CastShadow = false,false,false,false
visual.Size = Vector3.new(0.1,0.1, distance)
visual.CFrame = CFrame.lookAt(A, B) * CFrame.new(0,0,-distance/2)
visual.Name = "bullet"
visual.Parent = workspace

game:GetService("Debris"):AddItem(visual, 0.1)
end

remote_event.OnServerEvent:Connect(function(player, mouse_position)
-- cast ray
local origin = fire_point.WorldPosition
local direction = (mouse_position - origin).Unit
local distance = 100

local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Exclude
params.FilterDescendantsInstances = {tool.Parent}

local result = workspace:Raycast(origin, direction*distance, params)

if result then
visualise(origin, result.Position)

local hit = result.Instance
if hit.Parent:FindFirstChild("Humanoid") then
hit.Parent:FindFirstChild("Humanoid"):TakeDamage(20)
end
else
visualise(origin, origin + direction * distance)
end
end)

GunClient:

local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()

local tool = script.Parent

local remote_event = tool:WaitForChild("FireGun")

tool.Activated:Connect(function()
remote_event:FireServer(mouse.Hit.Position)
end)