-
What do you want to achieve? Keep it simple and clear!
i want my raycast bullet only damaging once -
What is the issue? Include screenshots / videos if possible!
my raycast damage got multiply everytimes it hits something
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
i did look up for some tutorials, and some dev forum posts that also have the same problem,but non of it works
the script below i took from a youtube tutorial and i follow it,i compared both script but couldnt find the differences
local tool = script.Parent
local fireEvent = tool["fire(car)"]
local FastCast = require(tool.FastCastRedux)
local firePoint = tool.metals["fire point"]
local bulletsFolder = workspace:FindFirstChild("BulletFolder") or Instance.new("Folder", workspace)
bulletsFolder.Name = "BulletFolder"
local bulletTemplate = Instance.new("Part")
bulletTemplate.Anchored = true
bulletTemplate.CanCollide = false
bulletTemplate.Shape = "Ball"
bulletTemplate.Size = Vector3.new(0.2,0.2,0.2)
bulletTemplate.Material = Enum.Material.Glass
bulletTemplate.Color = Color3.fromRGB(14, 21, 34)
FastCast.VisualizeCasts = true
local caster = FastCast.new()
local castParams = RaycastParams.new()
castParams.FilterType = Enum.RaycastFilterType.Exclude
castParams.IgnoreWater = true
local castBehavior = FastCast.newBehavior()
castBehavior.RaycastParams = castParams
castBehavior.Acceleration = Vector3.new(0, -workspace.Gravity, 0)
castBehavior.AutoIgnoreContainer = false
castBehavior.CosmeticBulletContainer = bulletsFolder
--castBehavior.CosmeticBulletTemplate = bulletTemplate
local function onEquipped()
castParams.FilterDescendantsInstances = {tool.Parent, bulletsFolder}
end
fireEvent.OnServerEvent:Connect(function(player, mousePosition)
local origin = firePoint.WorldPosition
local direction = (mousePosition - origin).Unit
caster:Fire(origin, direction, 1000, castBehavior)
firePoint.Muzzle:Emit(50)
firePoint.Smoke:Emit(10)
tool.metals.frizzen.friz:Emit(50)
end)
caster.RayHit:Connect(function(cast, result, velocity, bullet)
local hit = result.Instance
print(hit)
local character = hit:FindFirstAncestorWhichIsA("Model")
if character and character:FindFirstChild("Humanoid") then
character.Humanoid:TakeDamage(60)
end
game:GetService("Debris"):AddItem(bullet, .5)
end)
caster.LengthChanged:Connect(function(cast, lastPoint, direction, length, velocity, bullet)
if bullet then
local bulletLength = bullet.Size.Z/2
local offset = CFrame.new(0, 0, -(length - bulletLength))
bullet.CFrame = CFrame.lookAt(lastPoint, lastPoint + direction):ToWorldSpace(offset)
end
end)
tool.Equipped:Connect(onEquipped)
local script
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local char = plr.Character
while not char or not char.Parent do
char = plr.Character
wait()
end
local hum = char:WaitForChild("Humanoid")
local tool = script.Parent
local ustype = game:GetService("UserInputService")
local fireRemote = tool["fire(car)"]
local plrGUI = plr:WaitForChild("PlayerGui")
local instruc = plrGUI:FindFirstChild("InstructionForGuns")
local mobileGUI = plrGUI:FindFirstChild("MBgun")
local cancelB = mobileGUI:WaitForChild("Cancel")
local aimB = mobileGUI:WaitForChild("Aim")
local fireB = mobileGUI:WaitForChild("Fire")
local reloadB = mobileGUI:WaitForChild("Reload")
local blockingVal = char:WaitForChild("Blocking")
local isPC = ustype.KeyboardEnabled and not ustype.TouchEnabled
local isMB = ustype.TouchEnabled and not ustype.KeyboardEnabled
local animTrack = {
idleT = hum:LoadAnimation(tool.anims.idle);
equipT = hum:LoadAnimation(tool.anims.equip);
readyT = hum:LoadAnimation(tool.anims.ready);
aimT = hum:LoadAnimation(tool.anims.aim);
fireT = hum:LoadAnimation(tool.anims.fire);
cancelT = hum:LoadAnimation(tool.anims.cancel);
reloadT = hum:LoadAnimation(tool.anims.reload);
blockT = hum:LoadAnimation(tool.anims.block)
}
local isReloadingValue = tool:FindFirstChild("IsReloading")
local outBullet = tool:FindFirstChild("OutOfBullet")
local isBlocking = tool:FindFirstChild("IsBlocking")
local canShoot = false
local isReady = false
local isEquipped = false
local inAction = false
local canBlock = true
local function equip()
mouse.Icon = "http://www.roblox.com/asset/?id=15594214036"
isEquipped = true
print("equipped")
animTrack.equipT:Play()
tool.BodyAttach.equip:Play()
wait(.2)
animTrack.idleT:Play()
if isPC and not isMB then
instruc.Enabled = true
print("pc")
end
if isMB and not isPC then
mobileGUI.Enabled = true
aimB.Visible = true
reloadB.Visible = true
print("mobile")
elseif isMB and outBullet.Value then
aimB.Visible = false
reloadB.Visible = true
print("out of bullet on mb")
end
return true
end
local function makeReady()
if isEquipped and not isReady and not isReloadingValue.Value and inAction == false and not isBlocking.Value then
print("is ready")
inAction = true
animTrack.idleT:Stop()
animTrack.equipT:Stop()
animTrack.readyT:Play()
animTrack.readyT:GetMarkerReachedSignal("pull h"):Connect(function()
tool.BodyAttach.pullH:Play()
end)
wait(.5)
animTrack.aimT:Play()
hum.WalkSpeed = 8
isReady = true
canShoot = true
inAction = false
if isMB then
fireB.Visible = true
cancelB.Visible = true
aimB.Visible = false
end
end
end
local function reloading()
if isEquipped and outBullet.Value and not isReloadingValue.Value and inAction == false and not isBlocking.Value then
print("proceed reloading")
isReloadingValue.Value = true
animTrack.idleT:Play()
animTrack.reloadT:Play()
animTrack.aimT:Stop()
inAction = true
animTrack.reloadT:GetMarkerReachedSignal("start"):Connect(function()
canShoot = false
outBullet.Value = true
canBlock = false
hum.WalkSpeed = 12
end)
animTrack.reloadT:GetMarkerReachedSignal("pull h"):Connect(function()
tool.BodyAttach.pullH:Play()
end)
animTrack.reloadT:GetMarkerReachedSignal("pull f"):Connect(function()
tool.BodyAttach.pullF:Play()
end)
animTrack.reloadT:GetMarkerReachedSignal("ripped"):Connect(function()
tool.BodyAttach.rippedPapaer:Play()
tool.BodyAttach.spit:Play()
end)
animTrack.reloadT:GetMarkerReachedSignal("pour"):Connect(function()
tool.BodyAttach.pourpow:Play()
end)
animTrack.reloadT:GetMarkerReachedSignal("place"):Connect(function()
tool.BodyAttach.placecart:Play()
end)
animTrack.reloadT:GetMarkerReachedSignal("pull rod"):Connect(function()
tool.BodyAttach.pullrod:Play()
end)
animTrack.reloadT:GetMarkerReachedSignal("rod in"):Connect(function()
tool.BodyAttach.rodin:Play()
end)
animTrack.reloadT:GetMarkerReachedSignal("slam"):Connect(function()
tool.BodyAttach.slam:Play()
end)
animTrack.reloadT:GetMarkerReachedSignal("stop"):Connect(function()
isReloadingValue.Value = false
outBullet.Value = false
isReady = false
hum.WalkSpeed = 16
canBlock = true
inAction = false
end)
elseif isMB and outBullet.Value and inAction == false then
fireB.Visible = false
cancelB.Visible = false
aimB.Visible = false
reloadB.Visible = true
end
end
local function unequip()
hum.WalkSpeed = 16
isEquipped = false
canShoot = false
isReady = false
canBlock = false
isReloadingValue.Value = false
isBlocking.Value = false
blockingVal.Value = false
inAction = false
animTrack.idleT:Stop()
animTrack.aimT:Stop()
animTrack.fireT:Stop()
animTrack.equipT:Stop()
animTrack.readyT:Stop()
animTrack.cancelT:Stop()
animTrack.reloadT:Stop()
instruc.Enabled = false
mobileGUI.Enabled = false
mouse.Icon = ""
end
local function cancelAiming()
if isEquipped and isReady and not isReloadingValue.Value and inAction == false then
print("remove the aim")
inAction = true
animTrack.readyT:Stop()
animTrack.aimT:Stop()
animTrack.cancelT:Play()
animTrack.cancelT:GetMarkerReachedSignal("pull h"):Connect(function()
tool.BodyAttach.pullH:Play()
end)
hum.WalkSpeed = 16
canShoot = false
wait(.5)
animTrack.idleT:Play()
animTrack.aimT:Stop()
isReady = false
inAction = false
if isMB then
aimB.Visible = true
fireB.Visible = false
cancelB.Visible = false
end
end
end
local function shoot()
if isEquipped and canShoot and isReady and not isReloadingValue.Value and not outBullet.Value and not isBlocking.Value and inAction == false then
print("proceed firing")
inAction = true
animTrack.idleT:Stop()
animTrack.fireT:Play()
animTrack.fireT:GetMarkerReachedSignal("fire"):Connect(function()
fireRemote:FireServer(mouse.Hit.Position)
tool.BodyAttach.fire:Play()
end)
wait(1.2)
animTrack.idleT:Play()
outBullet.Value = true
animTrack.cancelT:Play()
inAction = false
animTrack.aimT:Stop()
isReady = false
canShoot = false
hum.WalkSpeed = 16
elseif isMB and outBullet.Value then
fireB.Visible = false
cancelB.Visible = false
aimB.Visible = true
reloadB.Visible = true
end
end
mouse.Button1Down:Connect(function()
if isPC and not isMB then
shoot()
end
end)
mouse.Button2Up:Connect(makeReady)
mouse.Button2Down:Connect(cancelAiming)
ustype.InputBegan:Connect(function(input)
if ustype:GetFocusedTextBox() then
return
end
if input.KeyCode == Enum.KeyCode.R then
print("pressed r")
reloading()
end
end)
tool.Equipped:Connect(equip)
tool.Unequipped:Connect(unequip)
fireB.Activated:Connect(shoot)
aimB.Activated:Connect(makeReady)
cancelB.Activated:Connect(cancelAiming)
reloadB.Activated:Connect(reloading)