Line 50 gives error upon firing Unable to cast Instance of bool
wait (1)
local LightControl = Instance.new("RemoteEvent")
LightControl.Name = "LightControl"
LightControl.Parent = game.ReplicatedStorage
local PKF = Instance.new("RemoteEvent")
PKF.Name = "PhaserHarmFire"
PKF.Parent = game.ReplicatedStorage
local PSF = Instance.new("RemoteEvent")
PSF.Name = "PhaserStunFire"
PSF.Parent = game.ReplicatedStorage
local WKF = Instance.new("RemoteEvent")
WKF.Name = "WidebeamHarmFire"
WKF.Parent = game.ReplicatedStorage
local WSF = Instance.new("RemoteEvent")
WSF.Name = "WidebeamStunFire"
WSF.Parent = game.ReplicatedStorage
-- create ignore list
local IgnoreList = {}
for i, v in pairs (workspace:GetDescendants()) do
if v:IsA('BasePart') and v.CanCollide == false and v.Transparency == 1 then
table.insert(IgnoreList, #IgnoreList + 1, v)
end
end
-- Light Control
--game.ReplicatedStorage.LightControl.OnServerEvent:connect(function(player, tool)
--function on(tool)
--tool.Light.SpotLight.Enabled = true
--end
--function off(tool)
--tool.Light.SpotLight.Enabled = false
--end
--end)
-- Various Wep Settings
game.ReplicatedStorage.PhaserStunFire.OnServerEvent:connect(function(player, mousehit, Tool, tip, char)
if Tool.CurrentCharge.Value >= 10 then
Tool.CurrentCharge.Value = Tool.CurrentCharge.Value - 10
local ray = Ray.new(tip.CFrame.p, (mousehit - tip.CFrame.p).unit * 100)
local impact, position = workspace:FindPartOnRayWithIgnoreList(ray, IgnoreList, char, false, true)
print ("Beam Creation")
local beam = Instance.new("Part", workspace)
beam.BrickColor = BrickColor.new("Steel blue")
beam.Material = "Neon"
beam.Transparency = 0.95
beam.Anchored = true
beam.Locked = true
beam.CanCollide = false
local StunBeamFX = Tool.Handle.StunBeamFX:Clone()
StunBeamFX.Parent = beam
StunBeamFX.Enabled = true
Tool.Handle.shot:Play()
game:GetService("Debris"):AddItem(beam, 0.15)
local distance = (tip.CFrame.p - position).magnitude
beam.Size = Vector3.new(0.1, distance, 0.1)
beam.CFrame = CFrame.new(tip.CFrame.p, position) * CFrame.new(0, 0, -distance / 2) * CFrame.Angles(math.rad(90),0,0)
if impact then
local humanoid = impact.Parent:FindFirstChild("Humanoid")
if not humanoid then
humanoid = impact.Parent.Parent:FindFirstChild("Humanoid")
end
if humanoid then
math.randomseed(tick())
local d = math.random(5,10)
humanoid:TakeDamage(d)
print(d)
else
local prt = Instance.new("Part")
prt.Transparency = 1
prt.Anchored = true
prt.Size = Vector3.new(0.2,0.2,0.2)
prt.Parent = game.Workspace
prt.Position = position
local StunFireFX = Tool.Handle.StunFireFX:clone()
StunFireFX.Parent = prt
StunFireFX.Enabled = true
local StunShotLight = Tool.Handle.StunShotLight:clone()
StunShotLight.Parent = prt
StunShotLight.Enabled = true
wait(0.5)
prt:Destroy()
end
end
end
end)
game.ReplicatedStorage.PhaserHarmFire.OnServerEvent:connect(function(player, mousehit, Tool, tip, char)
if Tool.CurrentCharge.Value >= 10 then
Tool.CurrentCharge.Value = Tool.CurrentCharge.Value - 10
local ray = Ray.new(tip.CFrame.p, (mousehit - tip.CFrame.p).unit * 100)
local impact, position = workspace:FindPartOnRay(ray, char, false, true)
print ("Beam Creation")
local beam = Instance.new("Part", workspace)
beam.BrickColor = BrickColor.new("Deep orange")
beam.Material = "Neon"
beam.Transparency = 0.95
beam.Anchored = true
beam.Locked = true
beam.CanCollide = false
local HarmBeamFX = Tool.Handle.HarmBeamFX:Clone()
HarmBeamFX.Parent = beam
HarmBeamFX.Enabled = true
Tool.Handle.shot:Play()
game:GetService("Debris"):AddItem(beam, 0.15)
local distance = (tip.CFrame.p - position).magnitude
beam.Size = Vector3.new(0.1, distance, 0.1)
beam.CFrame = CFrame.new(tip.CFrame.p, position) * CFrame.new(0, 0, -distance / 2) * CFrame.Angles(math.rad(90),0,0)
if impact then
local humanoid = impact.Parent:FindFirstChild("Humanoid")
if not humanoid then
humanoid = impact.Parent.Parent:FindFirstChild("Humanoid")
end
if humanoid then
math.randomseed(tick())
local d = math.random(5,10)
humanoid:TakeDamage(d)
print(d)
else
local prt = Instance.new("Part")
prt.Transparency = 1
prt.Anchored = true
prt.Size = Vector3.new(0.2,0.2,0.2)
prt.Parent = game.Workspace
prt.Position = position
local HarmFireFX = Tool.Handle.HarmFireFX:clone()
HarmFireFX.Parent = prt
HarmFireFX.Enabled = true
local HarmShotLight = Tool.Handle.HarmShotLight:clone()
HarmShotLight.Parent = prt
HarmShotLight.Enabled = true
wait(0.5)
prt:Destroy()
end
end
end
end)
