Hello, I’m trying to make raycast (bullets) for my guns in roblox studio. But I’m not sure where to start.
I want to try and Make Pistol, Automatic, and Shotgun Raycast. It also should be able to do damage the player.
Here is the Server:
local db = false
script.Parent.DealDamage.OnServerEvent:Connect(function(player, Target, Damage)
print("Damage Taken.")
Target.Humanoid:TakeDamage(Damage)
if Target.Humanoid.Health <= 0 then
if db == false then
db= true
player.leaderstats.Points.Value = player.leaderstats.Points.Value + 15
player.leaderstats.Kills.Value = player.leaderstats.Kills.Value + 1
task.wait(3)
db = false
end
end
end)
Client:
local tool = script.Parent
local maxammo = 13
local CoolDown = 0.23
local ammo = maxammo
local reloading = false
local plr = game.Players.LocalPlayer
local plrgui = plr:WaitForChild("PlayerGui")
local text = plrgui:WaitForChild("Ammo"):FindFirstChild("AmmoCount")
local Mouse = plr:GetMouse()
script.Parent.Equipped:Connect(function()
plr.CameraMode = Enum.CameraMode.LockFirstPerson
plrgui.Ammo.Enabled = true
text.DisableScript.Disabled = true
plrgui.Shop.Enabled = false
local function reload()
reloading = true
wait(1)
script.Parent.reload:Play()
ammo = maxammo
reloading = false
end
script.Parent.Activated:Connect(function()
local TargetPos = plr.Character:FindFirstChildOfClass("Humanoid").TargetPoint
if ammo > 0 and not reloading then
ammo = ammo - 1
script.Parent.gunshot:Play()
wait(CoolDown)
local targetHumanoid = Mouse.Target.Parent:FindFirstChild("Humanoid")
if targetHumanoid then
print("Fire.")
script.Parent.DealDamage:FireServer(Mouse.Target.Parent, math.random(15,30))
local player = game.Players.LocalPlayer
else
print("Shot wall, not player.")
end
elseif reloading == false then
reload()
script.Parent.gunshot:Stop()
end
while wait() do
text.Text = (ammo).." / "..tostring(maxammo)
end
end)
local input = game:GetService("UserInputService")
input.InputBegan:Connect(function(Key)
if Key.KeyCode == Enum.KeyCode.R and reloading == false and ammo ~= maxammo then
reload()
end
end)
local input = game:GetService("UserInputService")
input.InputBegan:Connect(function(Key)
if Key.KeyCode == Enum.KeyCode.ButtonY and reloading == false and ammo ~= maxammo then
reload()
end
end)
end)
script.Parent.Unequipped:Connect(function()
plrgui.Ammo.Enabled = false
text.DisableScript.Disabled = false
plrgui.Shop.Enabled = true
plr.CameraMode = Enum.CameraMode.Classic
end)
I’m not asking for someone to script for me, and just find something for me to script on my own.