|
| 13 Apr 2015 01:41 AM |
down = false mouse = game.Players.LocalPlayer:GetMouse()
mouse.Button1Up:connect(function() down = false end)
player = game.Players.LocalPlayer local tool = script.Parent local User debounce = false tool.Equipped:connect(function(mouse) user = tool.Parent mouse.Button1Down:connect(function() down = true debounce = true while down do while debounce do wait(.1) local ray = Ray.new(tool.Handle.CFrame.p, (mouse.Hit.p - tool.Handle.CFrame.p).unit * 300) local hit, position = game.Workspace:FindPartOnRay(ray, user) local humanoid = (hit and hit.Parent) and hit.Parent:FindFirstChild("Humanoid") or nil if humanoid then local user = game.Players:GetPlayerFromCharacter(hit.Parent) if user and user.TeamColor ~= player.TeamColor then --// You missed a reliability issue, what if user is nil? if player.Character.Humanoid.Health > 5 then humanoid:TakeDamage(5) end end end
local distance = (position - tool.Handle.CFrame.p).magnitude local rayPart = Instance.new("Part", user) rayPart.Name = "RayPart" rayPart.BrickColor = player.TeamColor 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.Handle.CFrame.p) * CFrame.new(0, 0, -distance/2)
game.Debris:AddItem(rayPart, 0.1)
end wait(.1) end end) debounce = false end)
Sad For My Sad |
|
|
| Report Abuse |
|
|
| |
|
rayk999
|
  |
| Joined: 18 Feb 2011 |
| Total Posts: 4705 |
|
|
| 13 Apr 2015 09:03 PM |
| Well, that's because you have the Button1Down always connected to the mouse. The Equipped event returns the mouse so you can just use the mouse that is returned from there |
|
|
| Report Abuse |
|
|
|
| 13 Apr 2015 09:07 PM |
Um. k. I don't know how to fix that. Since it's true and false values and functions. So..
Sad For My Sad |
|
|
| Report Abuse |
|
|
rayk999
|
  |
| Joined: 18 Feb 2011 |
| Total Posts: 4705 |
|
|
| 13 Apr 2015 09:08 PM |
| Just get rid of that first part that says mouse = game.Players.LocalPlayer:GetMouse() |
|
|
| Report Abuse |
|
|
|
| 13 Apr 2015 09:09 PM |
Doesn't it always have to get the mouse though? Or is that wrong with this script?
Sad For My Sad |
|
|
| Report Abuse |
|
|
|
| 13 Apr 2015 09:11 PM |
Because if I remove that, it says unknown global mouse.
Sad For My Sad |
|
|
| Report Abuse |
|
|
rayk999
|
  |
| Joined: 18 Feb 2011 |
| Total Posts: 4705 |
|
|
| 13 Apr 2015 09:12 PM |
| Put your button1Up event inside of the Equipped function |
|
|
| Report Abuse |
|
|
| |
|
rayk999
|
  |
| Joined: 18 Feb 2011 |
| Total Posts: 4705 |
|
|
| 13 Apr 2015 09:12 PM |
| Make sure everything that refers to mouse is inside the Equipped event |
|
|
| Report Abuse |
|
|
|
| 13 Apr 2015 09:14 PM |
*Face-Palm* Still not working when I am not holding it down....
down = false
player = game.Players.LocalPlayer local tool = script.Parent local User debounce = false tool.Equipped:connect(function(mouse) mouse.Button1Up:connect(function() down = false end) user = tool.Parent mouse.Button1Down:connect(function() down = true debounce = true while down do while debounce do wait(.1) local ray = Ray.new(tool.Handle.CFrame.p, (mouse.Hit.p - tool.Handle.CFrame.p).unit * 300) local hit, position = game.Workspace:FindPartOnRay(ray, user) local humanoid = (hit and hit.Parent) and hit.Parent:FindFirstChild("Humanoid") or nil if humanoid then local user = game.Players:GetPlayerFromCharacter(hit.Parent) if user and user.TeamColor ~= player.TeamColor then if player.Character.Humanoid.Health > 5 then humanoid:TakeDamage(5) end end end
local distance = (position - tool.Handle.CFrame.p).magnitude local rayPart = Instance.new("Part", user) rayPart.Name = "RayPart" rayPart.BrickColor = player.TeamColor 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.Handle.CFrame.p) * CFrame.new(0, 0, -distance/2)
game.Debris:AddItem(rayPart, 0.1)
end wait(.1) end end) debounce = false end)
Sad For My Sad |
|
|
| Report Abuse |
|
|
|
| 13 Apr 2015 09:16 PM |
Ok wtf. Not working.
Sad For My Sad |
|
|
| Report Abuse |
|
|
| |
|
iiEssence
|
  |
| Joined: 18 Jun 2014 |
| Total Posts: 3467 |
|
|
| 13 Apr 2015 09:39 PM |
Use the mouse from the parameter of .Equipped instead of getting the mouse from :GetMouse()
down = false
player = game.Players.LocalPlayer local tool = script.Parent local User debounce = false tool.Equipped:connect(function(mouse) user = tool.Parent mouse.Button1Down:connect(function() down = true debounce = true while down do while debounce do wait(.1) local ray = Ray.new(tool.Handle.CFrame.p, (mouse.Hit.p - tool.Handle.CFrame.p).unit * 300) local hit, position = game.Workspace:FindPartOnRay(ray, user) local humanoid = (hit and hit.Parent) and hit.Parent:FindFirstChild("Humanoid") or nil if humanoid then local user = game.Players:GetPlayerFromCharacter(hit.Parent) if user and user.TeamColor ~= player.TeamColor then --// You missed a reliability issue, what if user is nil? if player.Character.Humanoid.Health > 5 then humanoid:TakeDamage(5) end end end
local distance = (position - tool.Handle.CFrame.p).magnitude local rayPart = Instance.new("Part", user) rayPart.Name = "RayPart" rayPart.BrickColor = player.TeamColor 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.Handle.CFrame.p) * CFrame.new(0, 0, -distance/2)
game.Debris:AddItem(rayPart, 0.1)
end wait(.1) end end) mouse.Button1Up:connect(function() down = false end) debounce = false end) |
|
|
| Report Abuse |
|
|
|
| 13 Apr 2015 09:41 PM |
try
while down and tool.Equipped do |
|
|
| Report Abuse |
|
|
|
| 13 Apr 2015 09:46 PM |
| or maybe tool.Unequipped:connect(function() down=false end) |
|
|
| Report Abuse |
|
|