So this is my raygun script I have been working on. It has been working wonderfully until I had to make it so that they can't kill teammates. It just doesn't shoot at all. nothing shows up in output, and no errors pop up. What am I doing wrong? Sorry its a little disorderly.
tool.Equipped:connect(function(mouse) --store the character of the person using the tool user = tool.Parent --when the left mouse button is clicked mouse.Button1Down:connect(function() if d == false then d = true --make and do a hit test along the ray local ray = Ray.new(tool.Tip.CFrame.p, (mouse.Hit.p - tool.Tip.CFrame.p).unit*300) local hit, position = game.Workspace:FindPartOnRay(ray, user) local player = Game.Players.LocalPlayer ----------------------------------------------------------------------------------------------------------- local humanoid = hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") opponent = game.Players:FindFirstChild(hit.Parent.Name) if humanoid and humanoid.Health > 0 and hit.Parent ~= nil and game.Players:FindFirstChild(hit.Parent.Name) ~= nil and opponent.TeamColor ~= script.Parent.creator.Value.TeamColor then ---------------------------------------------------------------------------------------------------recently added part humanoid.Health = humanoid.Health - damage player.PlayerGui.Storage.Value = player.PlayerGui.Storage.Value + damage/2 --draw the ray local distance = (position - tool.Tip.CFrame.p).magnitude local rayPart = Instance.new("Part", user) rayPart.Name = "RayPart" rayPart.BrickColor = BrickColor.new("Bright green") rayPart.Transparency = 0.5 rayPart.Anchored = true rayPart.CanCollide = false rayPart.TopSurface = Enum.SurfaceType.Smooth rayPart.BottomSurface = Enum.SurfaceType.Smooth rayPart.formFactor = Enum.FormFactor.Custom rayPart.Size = Vector3.new(0.2, 0.2, distance) rayPart.CFrame = CFrame.new(position, tool.Tip.CFrame.p) * CFrame.new(0, 0, -distance/2) --add it to debris so it disappears after 0.1 seconds game.Debris:AddItem(rayPart, 0.1) wait(1) d = false end end end) end)
I'm pretty sure your problem is on Line.17. Change:
script.Parent.creator.Value.TeamColor then
to
game.Players:FindFirstChild(script.Parent.creator.Value).TeamColor