I’ve been working on a sentry system for my game, and I do not know how to proceed any further. I made a system where the sentry’s barrel faces the player, but I don’t really know how to make it shoot without becoming a minigun.
local TS = game:GetService("TweenService")
local RS = game:GetService("RunService")
local PS = game:GetService("Players")
local sentry = workspace.Sentry
local sentryFire = sentry.FiringPart
local burstCount = 5
local function attack(root)
print(root)
end
local function lookAt(root)
RS.Heartbeat:Connect(function(deltaTime)
local distance = (sentryFire.Position - root.HumanoidRootPart.Position).Magnitude
if distance < 20 then
sentryFire.CFrame = CFrame.lookAt(sentryFire.Position, root.HumanoidRootPart.Position)
return root
end
end)
end
game.Players.PlayerAdded:Connect(function(player)
local char = player.Character or player.CharacterAdded:Wait()
lookAt(char)
end)
Once it faces the player, use a part and fire it out at a velocity towards player using direction(partA.position - partB.position) and if it makes contact(detect using raycasts) do damage. Modules such as fast cast help optimize and improve projectiles. Also, you can add effects and sounds to the bullet for a better effect. Another alternative is just raycasting in a direction and dealing damage
Task.wait() or use delta
Delta can really be helpful with heartbeat
Runservice.Heartbeat:Connect(delta(this delta))
use this delta to caculate how much time passes between frames, and once enough time passes, fire sentry.
You can also use spawn(funciton)
Hope you find this helpful
it runs something that will not slow down other code ex.
while true do
wait(1)
print(“a”)
end
runs every second
while true do
spawn(function()
wait(1)
end)
print(“a”)
end
prints(“a”) every frame
no, maybe like a var named bullets shot in burst and adding 1 every time a bullet has been shot and if like 10 bullets have been shot, the increase burst, then at the end of that repeat.
if frame > burst then
start = os.time()
sentry.attack(firingPart, root)
bulletsShot += 1
if bursting == false then
bursting = false
burst=0.1
end
if bulletsShot == 10 then
bulletShots =0
burst = 2
bursting = false
--or just wait 2 and don't use the var bursting and just set burst to a fixed value
end
end
like this
sorry if this is unclear/ variables are confusing