You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
This round ending and starting successfully on an admins chat -
What is the issue? Include screenshots / videos if possible!
After I stop the event and start it again I get the error of:
attempt to index nil with 'Position'
the on chatted when they type “!EndEvent” it runs this
BindableEvent:Fire(false, 2)
and for start it runs
BindableEvent:Fire(true, 1)
Error is on
local target = FindNearest(rayOriginPart.Position)
Here is my main part of my code (server sided)
BindableEvent.Event:Connect(function(isRunning, id)
print("called with", id)
if running and isRunning then return end
running = isRunning
while running do
local target = FindNearest(rayOriginPart.Position)
if target then
Target = target.HumanoidRootPart
end
local origin = rayOriginPart.CFrame.Position
local rayTarget = target_previous:Lerp(Target.Position, laser_TrackingAccuracy)
local direction = (rayTarget - origin)
local results = workspace:Raycast(origin, direction * 100, raycastParameters)
if not results then
results = {Position = rayTarget}
else
if results.Instance.Parent:FindFirstChild("Humanoid") and not results.Instance:IsDescendantOf(workspace.HappyHome) and not results.Instance.Parent:IsA("Accessory") then
if debounce == false then
debounce = true
local targetChar = results.Instance.Parent
if targetChar then
takeDamage(targetChar.Humanoid)
else debounce = false
end
wait(1)
debounce = false
end
elseif results.Instance:IsDescendantOf(workspace.HappyHome) then
local NewDetector = Detector:Clone()
NewDetector.Parent = workspace
NewDetector.Position = results.Instance.Position
local PartsList = NewDetector:GetTouchingParts()
results.Instance:Destroy()
for _,Part in ipairs(PartsList) do
if Part:IsDescendantOf(workspace.HappyHome.Home.House) then
Part:BreakJoints()
Part:ApplyImpulse(math.random(1, 100), math.random(100, 500), math.random(1,100))
end
end
NewDetector:Destroy()
end
end
local distance = (results.Position - origin).Magnitude
local LaserPosition = laserPart.Position
LaserPart.Size = Vector3.new(laser_Thickness,laser_Thickness,distance)
laserPart.CFrame = CFrame.new(origin, results.Position) * CFrame.new(0,0, -distance/2)
target_previous = rayTarget
wait()
end
print("ending")
end)
thanks in advanced.