I was following Threasto’s Raycasting Gun Video when I saw that the Lazer Thingy isnt appearing when i shoot + the damage doesnt work
(go watch his video if u dont know what im talking about time stamp for it is around 8 minutes ish)
Could anyone help me here?
the script is stored in ServerScriptService
its a RegularScript
--Services
local replicatedStorage = game:GetService("ReplicatedStorage")
local debris = game:GetService("Debris")
--Variables
local remoteEvent = replicatedStorage.ToolRemote
local visualsFolder = game.Workspace.Visuals
--Create Bullet Line Thing (this is the part im having trouble with)
local function createVisual(startPosition, direction)
local center = startPosition + direction / 2
local distance = direction.Magnitude
local visual = Instance.new("Part")
visual.Parent = visualsFolder
visual.Anchored = true
visual.CanCollide = false
visual.BrickColor = BrickColor.new("New Yeller")
visual.Material = Enum.Material.Neon
visual.CFrame = CFrame.new(center, startPosition)
visual.Size = Vector3.new(0.5, 0.5, distance)
debris:AddItem(visual, 0.2)
end
--Damage n' Stuff
remoteEvent.OnServerEvent:Connect(function(player, tool, startPosition, endPosition)
local maxRange = tool:GetAttribute("MaxRange")
local damage = tool:GetAttribute("Damage")
local direction = (endPosition - startPosition).Unit * maxRange
local raycast = game.Workspace:Raycast(startPosition, direction)
if raycast then
print(raycast.Instance.Name)
local hitCharacter = raycast.Instance.Parent
local humanoid = hitCharacter:FindFirstChild("Humanoid")
if humanoid then
if hitCharacter.Name ~= player.Character.Name then
humanoid.Health -= damage
end
end
end
createVisual(startPosition, direction)
end)