bobaliny2
|
  |
| Joined: 12 May 2009 |
| Total Posts: 97 |
|
|
| 16 Mar 2014 12:21 AM |
In my game, I coded a sniper, and in the test mode for studio it works, but when I go to hit the 'Play' button of the game, the gun refuses to shoot or do anything. Any ideas?
Here is the script.
local tool = script.Parent local user
function postion(a, v, t, x) return .5*a*t^2 + v*t + x end
tool.Equipped:connect(function(mouse) user = tool.Parent
mouse.Button1Down:connect(function() local part = Instance.new("Part", user) part.Name = "RepresentingPart" part.FormFactor = "Custom" part.Size= Vector3.new(0.5,0.5,0.5) part.BrickColor = BrickColor.new("Really Black") part.Anchored = true part.CanCollide = false
local speed = 500 local gravity = Vector3.new(0,-32,0) local direction = (mouse.Hit.p - user.Head.Position).unit local initVelocity = speed*direction
local t = tick() local startingTime = t local hit = nil local hitpos = nil local lastPos = user.Head.Position
while not hit and t-startingTime < 3 do local pos = postion(gravity, initVelocity, t-startingTime, user.Head.Position) part.CFrame = CFrame.new(pos) hit, hitpos = workspace:FindPartOnRay(Ray.new(lastPos, (pos-lastPos).unit*(pos-lastPos).magnitude), user) wait() t = tick() lastPos = pos end
if hit then breakable = hit:FindFirstChild("isBreakable") hitVal = hit:FindFirstChild("numHit") if breakable ~= nil and breakable.Value == true then if hitVal.Value == 2 then hit:Destroy() part:Destroy() return end if hitVal.Value == 1 then hit.Material = "Ice" hitVal.Value = 2 end if hitVal.Value == 0 then hitVal.Value = 1 end end if hit.Parent:FindFirstChild("Health") ~= nil then local found = hit.Parent:FindFirstChild("Humanoid") local damage = 100 if found ~= nil then found.Health = found.Health - damage end end end
part:Destroy()
end) end) |
|
|
| Report Abuse |
|
|
| 16 Mar 2014 11:58 AM |
| Give this script to Scripting Helpers. |
|
|
| Report Abuse |
|
georgeba
|
  |
| Joined: 29 Oct 2011 |
| Total Posts: 1092 |
|
|
| 17 Mar 2014 12:41 PM |
| Hi There! This is the wrong forum, I would suggest going to scripting helpers forum. You would probably get a lot more replies there. |
|
|
| Report Abuse |
|