of     1   

Abs0luteZero
#63517744Monday, February 27, 2012 2:00 AM GMT

I'm trying to make a fishing pole that adds to your fish count. However, it doesn't work. The leaderboard works fine, and the pellets come out. I don't get any Fish points though. The pole works like a gun, if you shoot it into a part named "River", it's supposed to give you a point if you get lucky (1 out of 5 chance). Here is the Slingshot script: Tool = script.Parent VELOCITY = 85 -- constant local Pellet = Instance.new("Part") Pellet.Locked = true Pellet.BackSurface = 0 Pellet.BottomSurface = 0 Pellet.FrontSurface = 0 Pellet.LeftSurface = 0 Pellet.RightSurface = 0 Pellet.TopSurface = 0 Pellet.Shape = 0 Pellet.Size = Vector3.new(1,1,1) Pellet.BrickColor = BrickColor.new(21) script.Parent.PelletScript:clone().Parent = Pellet function fire(mouse_pos) Tool.Parent.Torso["Right Shoulder"].DesiredAngle = -100 Tool.Parent.Torso["Right Shoulder"].DesiredAngle = -150 Tool.Handle.SlingshotSound:play() -- find player's head pos local vCharacter = Tool.Parent local vPlayer = game.Players:playerFromCharacter(vCharacter) local head = vCharacter:findFirstChild("Head") if head == nil then return end local dir = mouse_pos - head.Position dir = computeDirection(dir) local launch = head.Position + 5 * dir local delta = mouse_pos - launch local dy = delta.y local new_delta = Vector3.new(delta.x, 0, delta.z) delta = new_delta local dx = delta.magnitude local unit_delta = delta.unit -- acceleration due to gravity in RBX units local g = (-9.81 * 20) local theta = computeLaunchAngle( dx, dy, g) local vy = math.sin(theta) local xz = math.cos(theta) local vx = unit_delta.x * xz local vz = unit_delta.z * xz local missile = Pellet:clone() missile.Position = launch missile.Velocity = Vector3.new(vx,vy,vz) * VELOCITY local creator_tag = Instance.new("ObjectValue") creator_tag.Value = vPlayer creator_tag.Name = "creator" creator_tag.Parent = missile missile.Parent = game.Workspace missile.PelletScript.Disabled = false end function computeLaunchAngle(dx,dy,grav) -- arcane -- http://en.wikipedia.org/wiki/Trajectory_of_a_projectile local g = math.abs(grav) local inRoot = (VELOCITY*VELOCITY*VELOCITY*VELOCITY) - (g * ((g*dx*dx) + (2*dy*VELOCITY*VELOCITY))) if inRoot <= 0 then return .25 * math.pi end local root = math.sqrt(inRoot) local inATan1 = ((VELOCITY*VELOCITY) + root) / (g*dx) local inATan2 = ((VELOCITY*VELOCITY) - root) / (g*dx) local answer1 = math.atan(inATan1) local answer2 = math.atan(inATan2) if answer1 < answer2 then return answer1 end return answer2 end function computeDirection(vec) local lenSquared = vec.magnitude * vec.magnitude local invSqrt = 1 / math.sqrt(lenSquared) return Vector3.new(vec.x * invSqrt, vec.y * invSqrt, vec.z * invSqrt) end Tool.Enabled = true function onActivated() if not Tool.Enabled then return end Tool.Enabled = false local character = Tool.Parent; local humanoid = character.Humanoid if humanoid == nil then print("Humanoid not found") return end local targetPos = humanoid.TargetPoint fire(targetPos) wait(1) Tool.Parent.Torso["Right Shoulder"].DesiredAngle = 100 Tool.Enabled = true end script.Parent.Activated:connect(onActivated) Pellet Script: function onTouched(hit) bob = script.Parent.creator bobby = game.Players:FindFirstChild(bob.Value) if hit.Name == "River" then print("water hit") i = math.random(1,5) if i == 1 then bobby.leaderstats.Fish.Value = bobby.leaderstats.Fish.Value script.Parent:remove() end script.Parent:remove() else print("no water") script.Parent:remove() end end script.Parent.Touched:connect(onTouched)
BunnyBoy26
#63518106Monday, February 27, 2012 2:05 AM GMT

You probably shouldn't use a free model to make this.
Abs0luteZero
#63518137Monday, February 27, 2012 2:05 AM GMT

The part I don't think is working is inside of the pellet script. I'm new to scripting and made the lines between the start of the function to the first script.Parent:remove() by myself. It's supposed to find the player that is in the Value created by the string inside the pellet made by the slingshot script, but it doesn't work. Help?
billbull7
#63518147Monday, February 27, 2012 2:05 AM GMT

You missed a +1 on value which made the fish count not go up. If thats all thats happening, this is most likely the problem function onTouched(hit) bob = script.Parent.creator bobby = game.Players:FindFirstChild(bob.Value) if hit.Name == "River" then print("water hit") i = math.random(1,5) if i == 1 then bobby.leaderstats.Fish.Value = bobby.leaderstats.Fish.Value + 1 --This is what adds to the fish count :) script.Parent:remove() end script.Parent:remove() else print("no water") script.Parent:remove() end end
Abs0luteZero
#63518722Monday, February 27, 2012 2:13 AM GMT

Oh of course, thx for letting me know! But, for some reason, when I add + 1, it doesn't shoot anymore. Help please?

    of     1