Now yes, this script has a bunch of unusable variables, but I stripped the raycasting from my gun system to create this script (which is a localscript.)

Anyways, when I test this online, it doesn't work, and I know where the problem is, but I don't know how to fix it. It's from line 06 to line 10.





local Selected;



--[[OnDead--]]
local Player = game.Players.LocalPlayer

Player.Character.Humanoid.Died:connect(function()
	Selected = false
end)
--^^This is where it bugs up^^--


local reticle;




script.Parent.Equipped:connect(function() --2 -- when its equipped m8 

Selected = true

reticle = game.ReplicatedStorage.SeriousRobloxEngine.gameplay.Reticle:Clone() -- Making the reticle actually exist

local settings = {
	["Gun_Name"] = "Pistol";
	["Time_Between_Shots"] = 1;
	["Reload_Time"] = 1.5;
	["Damage_Per_Shot"] = 100;
	["Bullet_Color"] = "Bright orange";
	["Bullet_Range"] = 125; -- (In studs)
	["Max_Ammo_In_Mag"] = 16;
	["Ammo_In_Mag"] = 16;
	["Hat_Destroy_Time"] = 1;
	["Time_Before_Bullet_Disappears"] = .005;
	["Shot_Sound"] = "131257506"; 
	["Reload_Sound"] = "138109513";
	["Tool_Tip"] = "";
	["Cast_Ray"] = false;
	["Shoot_Off_Hats"] = true;
	["Particles_On_Hit_Spot"] = true;
	["Turn_Particles_Red_If_A_Body_Is_Shot"] = true;
	["Bullet_Transparency"] = 0;
	["Amount_of_bullets"] = 1
}

local plr = game.Players.LocalPlayer
local gun = script.Parent;
local char = plr.Character
local uis = game:GetService("UserInputService")
local mouse = plr:GetMouse()
local handle = gun.Barrel
local r = game:GetService("RunService")
local db = false
local deathdb = false
local enabled = false

while Selected == true do
if Selected == true then
wait(0)
local collideRay = Ray.new(handle.CFrame.p, (mouse.Hit.p - handle.CFrame.p).unit * settings["Bullet_Range"])
local collidePart, positionPart = workspace:FindPartOnRay(collideRay, plr.Character, false, true)
			
local ignore = {plr.Character}
local ray = Ray.new(handle.CFrame.p, (mouse.Hit.p - handle.CFrame.p).unit * settings["Bullet_Range"])
local part, position = workspace:FindPartOnRayWithIgnoreList(ray, ignore, false, true)	
local distance = (handle.CFrame.p - position).magnitude	
	

			
			reticle.Parent = game.Workspace.CurrentCamera
			reticle.CFrame = CFrame.new(handle.CFrame.p, position) * CFrame.new(-0.2, 0, -distance / 2)
wait(0)
--reticle:destroy()
end
end
end) --2

script.Parent.Unequipped:connect(function() --1
	reticle:Destroy()
	Selected = false
end) --1

7 comments

0

Where is the problem?

0

Line 06 to line 10.

0

Try doing this on Line 8: (Player.Character or Player.CharacterAdded:wait()):WaitForChild("Humanoid").Died:connect(function()

0

Alright. The script is in a tool, btw. Hopefully this solution works.

0

Did not fix.

0

Is it a LocalScript?

0

Yes. Also, it's inside of a tool. And I believe I found the solution, but it has a chance of failing. I'm relying on a script within the character that deletes any tool within the character upon dying.