-
What do you want to achieve?
I am still somewhat new to LUA and I am trying to make it so when the brick that follows the mouse touches a ghost it always deals damage and not when you’re just up close or touch a specific spot. -
What is the issue?
It is very inconsistent where sometimes it starts damaging the ghost right off the bat, and then other times it just damages only in a specific spot or not at all until you get up close and even then it is very inconsistent.
-
What solutions have you tried so far?
I have been looking around the developer hub and I tried one thing with “GetTouchedParts” which didn’t seem to work on my case and I have heard some others thrown around such as Region3 and Raycasting but I was hoping to get a second opinion on what the problem could be.
Server Script in the Tool
local Players = game:GetService("Players")
local Tool = script.Parent.Parent
local Stream = script.Parent.Tip.Beam
local Tip2 = script.Parent:WaitForChild("Tip2")
local Barrel = script.Parent.Barrel
local Flash = script.Parent.Tip.ParticleEmitter
local MovingAtt = Tip2:WaitForChild("movingattachment")
local RunService = game:GetService("RunService")
local Fired = script.Parent.Parent.Fired
local CaptureStream = script.Parent.Parent.CaptureStream
local Released = script.Parent.Parent.Released
local AlignPositionInstance = Instance.new("AlignPosition")
local Debounce = false
local Debounce2 = false
local Ammunition = 0
-----------------------------------------------------------
Fired.OnServerEvent:Connect(function(Player,Mouse,MousePosition, Touched)
Stream.BeamLightning.Enabled = true
Stream.BeamCore.Enabled = true
Stream.BeamGlow.Enabled = true
Tip2.CanTouch = true
Tip2.CFrame = CFrame.new(MousePosition)
Flash.Enabled = true
Barrel.Fire.Playing = true
Barrel.StopFiring.Playing = false
Barrel.StopFiring.TimePosition = 0
if Touched ~= nil then
local GhostHumanoid = Touched.Parent:FindFirstChild("GhostHumanoid")
if Debounce2 == false and GhostHumanoid.Health >= 25 then
Debounce2 = true
GhostHumanoid.Health = GhostHumanoid.Health - 5
wait(1)
Debounce2 = false
end
end
end)
-----------------------------------------------------------
Released.OnServerEvent:Connect(function(Player, Touched)
Stream.BeamLightning.Enabled = false
Stream.BeamCore.Enabled = false
Stream.BeamGlow.Enabled = false
Barrel.Fire.Playing = false
Barrel.StopFiring.Playing = true
Barrel.Fire.TimePosition = 0
Flash.Enabled = false
Debounce2 = false
if Touched ~= nil then
local Torso = Touched.Parent:FindFirstChild("Torso")
local AlignPosition = Torso:FindFirstChild("AlignPosition")
local CaptureEffect = Torso:FindFirstChild("Captured")
if AlignPosition ~= nil then
Torso:SetNetworkOwner(nil)
AlignPosition.Parent = game.ServerStorage
Stream.BeamLightning.Attachment1 = MovingAtt
Stream.BeamCore.Attachment1 = MovingAtt
Stream.BeamGlow.Attachment1 = MovingAtt
CaptureEffect.Enabled = false
Flash.Enabled = false
end
end
end)
-----------------------------------------------------------
CaptureStream.OnServerEvent:Connect(function(Player, MousePosition, Touched)
local Torso = Touched.Parent:FindFirstChild("Torso")
local TorsoAttachment = Torso:FindFirstChild("Torso")
local CaptureEffect = Torso:FindFirstChild("Captured")
local Distance = 25
if Debounce == false then
AlignPositionInstance.Mode = Enum.PositionAlignmentMode.OneAttachment
AlignPositionInstance.RigidityEnabled = true
AlignPositionInstance.Attachment0 = TorsoAttachment
AlignPositionInstance.Parent = Torso
Debounce = true
local LV = CFrame.new(Tool.Handle.Tip.lasersource.WorldPosition,MousePosition)
local AlignPosition = Torso:FindFirstChild("AlignPosition")
AlignPosition.Position = Tool.Handle.Tip.lasersource.WorldPosition + LV.LookVector * Distance
Torso:SetNetworkOwner(Player)
Stream.BeamLightning.Attachment1 = TorsoAttachment
Stream.BeamCore.Attachment1 = TorsoAttachment
Stream.BeamGlow.Attachment1 = TorsoAttachment
CaptureEffect.Enabled = true
wait(1)
Debounce = false
end
end)
-----------------------------------------------------------