generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Problem with gun script

Previous Thread :: Next Thread 
evolvedpikachu is not online. evolvedpikachu
Joined: 18 Aug 2010
Total Posts: 10696
12 Aug 2013 03:50 PM
This works in every mode but Online, what did I do wrong? (There are 2 scripts, here is the first script)

s = script.Parent
ammo = script.Parent.AmmoGui:Clone()
stenanim = script.StenAnimate:Clone()
player = game.Players.LocalPlayer
character = player.Character
rs = character.Torso["Right Shoulder"]
ls = character.Torso["Left Shoulder"]
rh = character.Torso["Right Hip"]
lh = character.Torso["Left Hip"]
reload = false
isready = false
currentcamera = Workspace.CurrentCamera
q = false
e = false

s.Equipped:connect(function(mouse)
wait()
for i, v in ipairs(s.Handle:GetChildren()) do if v:IsA("Weld") then v:Destroy() end end
for i, v in ipairs(s.Clip1:GetChildren()) do if v:IsA("Weld") then v:Destroy() end end
for i, v in ipairs(character.Torso:GetChildren()) do if v:IsA("Motor6D") then v.MaxVelocity = 0.3 end end
if character:FindFirstChild("Animate") then
character.Animate.Disabled = true
end
function weld(part0,part1,c0)
local weld = Instance.new("Weld",part0)
for n,o in pairs({C0=c0,Part0=part0,Part1=part1})do
weld[n] = o
end
return weld end
rarm = character["Right Arm"]:Clone()
larm = character["Left Arm"]:Clone()

h = s.Handle
weld(h,s.BackSight1,CFrame.new(0.06,0.47,-0.7))
weld(h,s.BackSight2,CFrame.new(-0.06,0.47,-0.7))
weld(h,s.BackSightDecoration1,CFrame.new(0.06, 0.54, -0.7))
weld(h,s.BackSightDecoration2,CFrame.new(-0.06, 0.54, -0.7))
weld(h,s.BarrelHole,CFrame.new(0, 0.3, 1.53)*CFrame.Angles(math.rad(90),0,0))
weld(h,s.Body,CFrame.new(0,0.3,0.37)*CFrame.Angles(math.rad(90),0,0))
clip = weld(h,s.Clip1,CFrame.new(0.33,0.3,0.32)) -- Clip variable
weld(s.Clip1,s.Clip2,CFrame.new(0.154,0,0.008)*CFrame.Angles(0,math.rad(-11),0))
weld(s.Clip1,s.Clip3,CFrame.new(0.379,0,0.064)*CFrame.Angles(0,math.rad(-15),0))
weld(h,s.ClipHold,CFrame.new(0.27,0.3,0.32))
weld(h,s.ClipHole,CFrame.new(0.3,0.3,0.32))
weld(h,s.FakeHandle,CFrame.new(0,0,0)*CFrame.Angles(math.rad(20),0,0))
weld(h,s.FakeLight,CFrame.new(0,0.08,1.51)*CFrame.Angles(math.rad(90),0,0))
weld(h,s.FrontSight,CFrame.new(0,0.49,1.55))
weld(h,s.HandleDecoration1,CFrame.new(0,-0.188,-0.068)*CFrame.Angles(math.rad(20),0,0))
weld(h,s.HandleDecoration2,CFrame.new(0, -0.094, -0.034)*CFrame.Angles(math.rad(20),0,0))
weld(h,s.HandleDecoration3,CFrame.new(0,0,0)*CFrame.Angles(math.rad(20),0,0))
weld(h,s.Light,CFrame.new(0,0.08,1.51)*CFrame.Angles(math.rad(-180),0,0))
weld(h,s.Lighthold,CFrame.new(0,0.09,1.45))
weld(h,s.Stock1,CFrame.new(0,0.31,-1.24))
weld(h,s.Stock2,CFrame.new(0,0.14,-1.44))
weld(h,s.StockHold1,CFrame.new(0.19,0.31,-0.93))
weld(h,s.StockHold2,CFrame.new(-0.19,0.31,-0.93))
weld(h,s.StockHold3,CFrame.new(0,0.31,-1.04))
weld(h,s.StockHold4,CFrame.new(-0.149, 0.31, -0.754)*CFrame.Angles(0,math.rad(39),0))
weld(h,s.StockHold5,CFrame.new(0.153, 0.31, -0.758)*CFrame.Angles(0,math.rad(-39),0))
weld(h,s.Trigger,CFrame.new(0,0.11,0.258)*CFrame.Angles(math.rad(-9),0,0))
weld(h,s.Triggercover,CFrame.new(0,0.1,0.4))
weld(h,s.TriggercoverBottom,CFrame.new(0,0.01,0.27))
rarm.Parent = script.Parent
larm.Parent = script.Parent
rarm.Transparency = 0.3
larm.Transparency = 0.3
rarm.CanCollide = false
larm.CanCollide = false
rarm.Name = "FakeRight"
larm.Name = "FakeLeft"
weld(character["Right Arm"],rarm,CFrame.new(0,0,0))
weld(character["Left Arm"],larm,CFrame.new(0,0,0))
ammo.Parent = game.Players.LocalPlayer.PlayerGui
wait()
ls:SetDesiredAngle(math.rad(-90))
lh:SetDesiredAngle(0)
rh:SetDesiredAngle(0)
rs:SetDesiredAngle(math.rad(90))
rs.C0 = CFrame.new(0.6,0.4,rs.C0.Z)*CFrame.Angles(0,math.rad(105),0)
ls.C0 = CFrame.new(-0.2, 0.6, -0.5)*CFrame.Angles(0,math.rad(-100),0)
character["Right Arm"].Transparency = 1
character["Left Arm"].Transparency = 1
stenanim.Parent = character
stenanim.Disabled = false
mouse.Icon = "rbxasset://textures\\GunCursor.png"
isready = true

bdown = false
mouse.Button1Down:connect(function()
if isready == true then
damage = true
function GetBullet(hit)
local ignore = character:GetChildren()
for i, v in ipairs(hit.Parent:GetChildren()) do
for i = 1, #ignore do
if ignore[i] == hit then
damage = false
end
end
if v:IsA("Humanoid") and damage == true then
v:TakeDamage(math.random(3,7))
end
end
end
bdown = true
while bdown and wait(0.15) and script.Parent.Ammo.Value > 0 and reload == false do
local mH = mouse.Hit
local pa = Instance.new("Part",Workspace)
local v = Instance.new("BodyVelocity",pa)
local sound = Instance.new("Sound",script.Parent.Handle)
local sw = coroutine.wrap(function()repeat wait() until sound.IsPlaying == false sound:Destroy() end)
local w = coroutine.wrap(function() wait(5) if pa ~= nil then pa:Destroy() end end)
local cc = coroutine.wrap(function() currentcamera.Focus = CFrame.new(currentcamera.Focus.X+0.015,currentcamera.Focus.Y+0.025,currentcamera.Focus.Z) wait(0.05) currentcamera.Focus = CFrame.new(currentcamera.Focus.X-0.01,currentcamera.Focus.Y-0.02,currentcamera.Focus.Z) end)
script.Parent.Ammo.Value = script.Parent.Ammo.Value - 1
pa.FormFactor = 3
pa.Size = Vector3.new(.2,.2,.2)
pa.BrickColor = BrickColor.DarkGray()
pa.CFrame = script.Parent.Handle.CFrame * CFrame.new(script.Parent.Parent.Torso.CFrame.lookVector * 2)
pa.CFrame = CFrame.new(pa.Position, mH.p)
v.maxForce = Vector3.new(10000,10000,10000)
v.P = 6000
v.velocity = pa.CFrame.lookVector * 120
pa.Touched:connect(GetBullet)
sound.SoundId = "http://www.roblox.com/asset/?id=13510352"
sound.Pitch = 1
sound.Volume = 1
sound:Play()
cc()
w()
sw()
end
end
end)

mouse.Button1Up:connect(function()
bdown = false
end)

mouse.KeyDown:connect(function(key)
if key == "r" and bdown == false and reload == false and s.Ammo.Value ~= s.MaxAmmo.Value and isready == true then
reload = true
local sound = Instance.new("Sound",script.Parent.Handle)
sound.SoundId = "http://www.roblox.com/asset/?id=2697432"
sound.Volume = 1
sound:Play()
for i = 1, 8 do
wait(0.05)
clip.C0 = CFrame.new(clip.C0.X+0.1,clip.C0.Y,clip.C0.Z)
ls.C0 = CFrame.new(ls.C0.X-0.1,ls.C0.Y,ls.C0.Z)*CFrame.Angles(0,math.rad(-100),0)
end
s.Clip1.Transparency = 1
s.Clip2.Transparency = 1
s.Clip3.Transparency = 1
ls:SetDesiredAngle(math.rad(-15))
wait(0.38)
ls:SetDesiredAngle(math.rad(-90))
wait(0.4)
s.Clip1.Transparency = 0
s.Clip2.Transparency = 0
s.Clip3.Transparency = 0
for i = 1, 8 do
wait(0.05)
clip.C0 = CFrame.new(clip.C0.X-0.1,clip.C0.Y,clip.C0.Z)
ls.C0 = CFrame.new(ls.C0.X+0.1,ls.C0.Y,ls.C0.Z)*CFrame.Angles(0,math.rad(-100),0)
end
script.Parent.Ammo.Value = script.Parent.MaxAmmo.Value
sound:Destroy()
reload = false
elseif key == "f" and reload == false and bdown == false then
if s.Light.SpotLight.Enabled == false and reload == false and bdown == false then
ls.C0 = CFrame.new(ls.C0.X,ls.C0.Y,ls.C0.Z-0.5)*CFrame.Angles(0,math.rad(-100),0)
s.Light.SpotLight.Enabled = true
wait(0.1)
ls.C0 = CFrame.new(ls.C0.X,ls.C0.Y,ls.C0.Z+0.5)*CFrame.Angles(0,math.rad(-100),0)
elseif s.Light.SpotLight.Enabled == true and reload == false and bdown == false then
ls.C0 = CFrame.new(ls.C0.X,ls.C0.Y,ls.C0.Z-0.5)*CFrame.Angles(0,math.rad(-100),0)
s.Light.SpotLight.Enabled = false
wait(0.1)
ls.C0 = CFrame.new(ls.C0.X,ls.C0.Y,ls.C0.Z+0.5)*CFrame.Angles(0,math.rad(-100),0)
end
elseif key == "q" then
q = true
if rarm.Transparency < 0.8 and larm.Transparency < 0.8 then
rarm.Transparency = rarm.Transparency + 0.05
larm.Transparency = larm.Transparency + 0.05
wait(0.3)
if q == true then
repeat
wait(0.1)
if q == true and rarm.Transparency < 0.7 and larm.Transparency < 0.7 then
rarm.Transparency = rarm.Transparency + 0.05
larm.Transparency = larm.Transparency + 0.05
end
until q == false
end
elseif rarm.Transparency == 1 and larm.Transparency == 1 then
character["Right Arm"].Transparency = 0
character["Left Arm"].Transparency = 0
end
elseif key == "e" then
e = true
if rarm.Transparency ~= 0 and larm.Transparency ~= 0 then
rarm.Transparency = rarm.Transparency - 0.05
larm.Transparency = larm.Transparency - 0.05
wait(0.3)
if e == true then
repeat
wait(0.1)
if e == true and rarm.Transparency > 0 and larm.Transparency > 0 then
rarm.Transparency = rarm.Transparency - 0.05
larm.Transparency = larm.Transparency - 0.05
end
until e == false
end
elseif rarm.Transparency == 0 and larm.Transparency == 0 then
character["Right Arm"].Transparency = 1
character["Left Arm"].Transparency = 1
end
end
end)
mouse.KeyUp:connect(function(key)
if key == "q" and isready == true then
q = false
elseif key == "e" and isready == true then
e = false
end
end)
end)

s.Unequipped:connect(function()
function clear(parent,object)
for i, v in ipairs(parent:GetChildren()) do
if v:IsA(object) then
v:Destroy()
end
end
end
character.Animate.Disabled = false
for i, v in ipairs(character.Torso:GetChildren()) do if v:IsA("Motor6D") then v.MaxVelocity = 0.1 end end
if script.Parent.Parent ~= Workspace then
clear(s.Handle,"Weld")
clear(s.Clip1,"Weld")
clear(character["Right Arm"],"Weld")
clear(character["Left Arm"],"Weld")
rarm:Destroy()
larm:Destroy()
character["Right Arm"].Transparency = 0
character["Left Arm"].Transparency = 0
end
clear(s.Handle,"Sound")
ammo.Parent = nil
ls.C0 = CFrame.new(-1, 0.5, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0)
rs.C0 = CFrame.new(1, 0.5, 0, 0, 0, 1, 0, 1, 0, -1, -0, -0)
stenanim.Parent = nil
isready = false
end)

s.Ammo.Changed:connect(function()
ammo.Ammo.Text = tostring(s.Ammo.Value).."/"..tostring(s.MaxAmmo.Value)
end)
Report Abuse
evolvedpikachu is not online. evolvedpikachu
Joined: 18 Aug 2010
Total Posts: 10696
12 Aug 2013 03:51 PM
Second script (StenAnimate, basically Animate with stuff deleted):

function waitForChild(parent, childName)
local child = parent:findFirstChild(childName)
if child then return child end
while true do
child = parent.ChildAdded:wait()
if child.Name==childName then return child end
end
end

-- ANIMATION

-- declarations

local Figure = script.Parent
local Torso = waitForChild(Figure, "Torso")
local RightHip = waitForChild(Torso, "Right Hip")
local LeftHip = waitForChild(Torso, "Left Hip")
local Neck = waitForChild(Torso, "Neck")
local Humanoid = waitForChild(Figure, "Humanoid")
local pose = "Standing"

local toolAnim = "None"
local toolAnimTime = 0

local jumpMaxLimbVelocity = 0.75

-- functions

function onRunning(speed)
if speed>0 then
pose = "Running"
else
pose = "Standing"
end
end

function onDied()
pose = "Dead"
end

function onJumping()
pose = "Jumping"
end

function onClimbing()
pose = "Climbing"
end

function onGettingUp()
pose = "GettingUp"
end

function onFreeFall()
pose = "FreeFall"
end

function onFallingDown()
pose = "FallingDown"
end

function onSeated()
pose = "Seated"
end

function onPlatformStanding()
pose = "PlatformStanding"
end

function onSwimming(speed)
if speed>0 then
pose = "Running"
else
pose = "Standing"
end
end

function moveJump()
RightHip:SetDesiredAngle(0)
LeftHip:SetDesiredAngle(0)
end


-- same as jump for now

function moveFreeFall()
RightHip:SetDesiredAngle(0)
LeftHip:SetDesiredAngle(0)
end

function moveSit()
RightHip:SetDesiredAngle(3.14 /2)
LeftHip:SetDesiredAngle(-3.14 /2)
end

function getTool()
for _, kid in ipairs(Figure:GetChildren()) do
if kid.className == "Tool" then return kid end
end
return nil
end

function getToolAnim(tool)
for _, c in ipairs(tool:GetChildren()) do
if c.Name == "toolanim" and c.className == "StringValue" then
return c
end
end
return nil
end

function animateTool()

if (toolAnim == "None") then
return
end

if (toolAnim == "Slash") then
return
end

if (toolAnim == "Lunge") then
RightHip.MaxVelocity = 0.5
LeftHip.MaxVelocity = 0.5
RightHip:SetDesiredAngle(1.57)
LeftHip:SetDesiredAngle(1.0)
return
end
end

function move(time)
local amplitude
local frequency

if (pose == "Jumping") then
moveJump()
return
end

if (pose == "FreeFall") then
moveFreeFall()
return
end

if (pose == "Seated") then
moveSit()
return
end

local climbFudge = 0

if (pose == "Running") then
amplitude = 1
frequency = 9
elseif (pose == "Climbing") then
amplitude = 1
frequency = 9
climbFudge = 3.14
else
amplitude = 0.1
frequency = 1
end

desiredAngle = amplitude * math.sin(time*frequency)

RightHip:SetDesiredAngle(-desiredAngle)
LeftHip:SetDesiredAngle(-desiredAngle)


local tool = getTool()

if tool then

animStringValueObject = getToolAnim(tool)

if animStringValueObject then
toolAnim = animStringValueObject.Value
-- message recieved, delete StringValue
animStringValueObject.Parent = nil
toolAnimTime = time + .3
end

if time > toolAnimTime then
toolAnimTime = 0
toolAnim = "None"
end

animateTool()


else
toolAnim = "None"
toolAnimTime = 0
end
end


-- connect events

Humanoid.Died:connect(onDied)
Humanoid.Running:connect(onRunning)
Humanoid.Jumping:connect(onJumping)
Humanoid.Climbing:connect(onClimbing)
Humanoid.GettingUp:connect(onGettingUp)
Humanoid.FreeFalling:connect(onFreeFall)
Humanoid.FallingDown:connect(onFallingDown)
Humanoid.Seated:connect(onSeated)
Humanoid.PlatformStanding:connect(onPlatformStanding)
Humanoid.Swimming:connect(onSwimming)
-- main program

local runService = game:service("RunService");

while Figure.Parent~=nil do
local _, time = wait(0.1)
move(time)
end


Report Abuse
MikeAnIkes is not online. MikeAnIkes
Joined: 13 Mar 2010
Total Posts: 1581
12 Aug 2013 03:53 PM
Hax fix: add wait(0.1) to the top of your first script.
Report Abuse
evolvedpikachu is not online. evolvedpikachu
Joined: 18 Aug 2010
Total Posts: 10696
12 Aug 2013 03:53 PM
Seems to break when I added this:

Variable:
stenanimate = script.StenAnimate:Clone()
Inside Equipped function:
stenanim.Parent = character
stenanim.Disabled = false
Inside Unequipped function:
stenanim.Parent = nil
Report Abuse
batpower54 is not online. batpower54
Joined: 04 Jun 2011
Total Posts: 1377
12 Aug 2013 03:53 PM
No one wants to read all that. Post the section that you are having a problem with.
Report Abuse
evolvedpikachu is not online. evolvedpikachu
Joined: 18 Aug 2010
Total Posts: 10696
12 Aug 2013 03:55 PM
@bat

My problem is posted above your post, I just added the full script because I added to more than one place.
Report Abuse
MikeAnIkes is not online. MikeAnIkes
Joined: 13 Mar 2010
Total Posts: 1581
12 Aug 2013 03:56 PM
Also, un-disable the script BEFORE you set the parent.
Report Abuse
evolvedpikachu is not online. evolvedpikachu
Joined: 18 Aug 2010
Total Posts: 10696
12 Aug 2013 04:03 PM
@Mike

Still not working. It worked before I added the stuff I mentioned in the 3rd post.

I gtg soon, going to check in probably a few hours/tomorrow.
Report Abuse
evolvedpikachu is not online. evolvedpikachu
Joined: 18 Aug 2010
Total Posts: 10696
12 Aug 2013 04:05 PM
Btw, the difference between Animate and StenAnimate is that StenAnimate doesn't mess with Right/Left Shoulder and that the variables have been taken out.
Report Abuse
expressmyself is not online. expressmyself
Joined: 19 Apr 2011
Total Posts: 1768
12 Aug 2013 04:07 PM
Do stenanim:Remove because you can stil reach it.
Report Abuse
evolvedpikachu is not online. evolvedpikachu
Joined: 18 Aug 2010
Total Posts: 10696
12 Aug 2013 08:38 PM
@express

No, parenting to nil is easier and is suggested:

http://wiki.roblox.com/index.php/Remove
Report Abuse
evolvedpikachu is not online. evolvedpikachu
Joined: 18 Aug 2010
Total Posts: 10696
12 Aug 2013 09:03 PM
bump, debug please.
Report Abuse
evolvedpikachu is not online. evolvedpikachu
Joined: 18 Aug 2010
Total Posts: 10696
12 Aug 2013 09:27 PM
bump of knowledge hunger
Report Abuse
evolvedpikachu is not online. evolvedpikachu
Joined: 18 Aug 2010
Total Posts: 10696
12 Aug 2013 10:56 PM
bump for the hunger of KNOWLEDGE AND LEDGES
Report Abuse
evolvedpikachu is not online. evolvedpikachu
Joined: 18 Aug 2010
Total Posts: 10696
13 Aug 2013 09:20 AM
dabupm
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image