iJava
|
  |
| Joined: 06 Mar 2011 |
| Total Posts: 29914 |
|
|
| 05 Jul 2016 04:15 AM |
My code for an FPS gun that I've been working on (it goes in StarterPlayerScripts) has 2 bugs that I've noticed, the first being sometimes when cloning the player's arms, they're yellow (probably their bodycolors have yet to load so it reverts to the default noob look), and also every couple respawns, the player's arms just glitch completely and the player doesn't get locked to first person, also the player's fake arms don't get welded to their body and the fake arms + gun just lie on the floor, resetting doesn't fix it, not sure the cause. Will pay 1,000 robux to the first person to fix these 2 glitches and clean up some other inefficiencies in my code (just scraping it together as I go along so it's pretty bad)
repeat wait() until game.ReplicatedStorage:findFirstChild("Data") ~= nil repeat wait() until game.ReplicatedStorage.Data:findFirstChild(game.Players.LocalPlayer.Name) ~= nil repeat wait() until game.Players.LocalPlayer.Character ~= nil
math.randomseed(os.time()%16)
local plr = game.Players.LocalPlayer local chr = plr.Character local right = chr:findFirstChild("Right Arm") local left = chr:findFirstChild("Left Arm") local torso = chr:findFirstChild("Torso") local data = game.ReplicatedStorage.Data:findFirstChild(plr.Name) local inGame = data:findFirstChild("In_Game") local reloading = false
repeat wait() until inGame ~= nil local container = workspace:FindFirstChild("LocalBin") if container == nil then container = Instance.new("Camera") container.Name = "LocalBin" container.Parent = workspace end local connections = {} function newConnection(func) table.insert(connections, func) end function disconnectAll() for i,v in pairs(connections) do v:disconnect() end connections = {} end function go() if inGame.Value then plr.CameraMode = Enum.CameraMode.LockFirstPerson
local fakeRight = right:clone() fakeRight.Parent = container local weld = Instance.new("Weld", chr) weld.Name = "Right_Weld" weld.Part0 = torso weld.Part1 = fakeRight local fakeLeft = left:clone() fakeLeft.Parent = container local weld2 = Instance.new("Weld", chr) weld2.Name = "Left_Weld" weld2.Part0 = torso weld2.Part1 = fakeLeft fakeLeft.Material = Enum.Material.SmoothPlastic fakeRight.Material = Enum.Material.SmoothPlastic fakeLeft.TopSurface = Enum.SurfaceType.Smooth fakeLeft.BottomSurface = Enum.SurfaceType.Smooth fakeRight.TopSurface = Enum.SurfaceType.Smooth fakeRight.BottomSurface = Enum.SurfaceType.Smooth weld.C0 = weld.C0 * CFrame.Angles(math.rad(90),0,math.rad(-5)) weld.C1 = weld.C1 * CFrame.new(-1.25,-.5,.25) weld2.C0 = weld2.C0 * CFrame.Angles(math.rad(90),0,math.rad(20)) weld2.C1 = weld2.C1 * CFrame.new(0,.75,.1) local gun = script.Handle:clone() gun.Parent = container local weld3 = Instance.new("Weld", chr) weld3.Name = "Gun_Weld" weld3.Part0 = torso weld3.Part1 = gun weld3.C0 = weld3.C0 * CFrame.Angles(math.rad(90),math.rad(180),math.rad(5)) weld3.C1 = weld3.C1 * CFrame.new(1,1.75,-1) newConnection(game:GetService("RunService").RenderStepped:connect(function() --local transparency stuff end)) else disconnectAll() plr.CameraMode = Enum.CameraMode.Classic for i,v in pairs(container:GetChildren()) do v:Destroy() end for i,v in pairs(chr:GetChildren()) do if v:IsA("Weld") then v:Destroy() end end end end go() inGame.Changed:connect(function() print("Value changed") go() end) chr.Humanoid.Died:connect(function() repeat wait() until plr.Character ~= nil repeat wait() until plr.Character.Parent == workspace repeat wait() until plr.Character.Humanoid ~= nil repeat wait() until plr.Character.Humanoid.Health >0 chr = plr.Character right = chr:findFirstChild("Right Arm") left = chr:findFirstChild("Left Arm") torso = chr:findFirstChild("Torso") reloading = false print("Going") go() end) function keyPress(input, event) if input.KeyCode == Enum.KeyCode.R and not reloading then --reload reloading = true local weld1 = chr:findFirstChild("Right_Weld") local weld2 = chr:findFirstChild("Left_Weld") local weld3 = chr:findFirstChild("Gun_Weld") coroutine.wrap(function() for i=1,3 do weld3.C0 = weld3.C0 * CFrame.Angles(math.rad(-5),0,0) weld1.C0 = weld1.C0 * CFrame.Angles(math.rad(5),0,0) wait(.01) end end)() wait(.01) coroutine.wrap(function() for i=1,5 do weld2.C0 = weld2.C0 * CFrame.Angles(0,0,math.rad(3)) wait(.01) end wait(.01) for i=1,25 do weld2.C0 = weld2.C0 * CFrame.Angles(math.rad(-1),0,0) wait(.01) end wait(.1) for i=1,25 do weld2.C0 = weld2.C0 * CFrame.Angles(math.rad(1),0,0) wait(.01) end for i=1,5 do weld2.C0 = weld2.C0 * CFrame.Angles(0,0,math.rad(-3)) wait(.01) end wait(.01) for i=1,3 do weld3.C0 = weld3.C0 * CFrame.Angles(math.rad(5),0,0) weld1.C0 = weld1.C0 * CFrame.Angles(math.rad(-5),0,0) wait(.01) end wait(.01) reloading = false end)() elseif input.KeyCode == Enum.KeyCode.O then plr.CameraMode = Enum.CameraMode.Classic end end game:GetService("UserInputService").InputBegan:connect(keyPress)
-Widths |
|
|
| Report Abuse |
|
|
CowInAJar
|
  |
| Joined: 27 Jun 2012 |
| Total Posts: 65 |
|
|
| 05 Jul 2016 04:50 AM |
1K seems like a lot for a bug fix...
\\ |
|
|
| Report Abuse |
|
|
iJava
|
  |
| Joined: 06 Mar 2011 |
| Total Posts: 29914 |
|
|
| 05 Jul 2016 02:04 PM |
well I can't figure it out and it provides some incentive to fix it
-Widths |
|
|
| Report Abuse |
|
|
Cinnace
|
  |
| Joined: 21 Jun 2016 |
| Total Posts: 370 |
|
|
| 05 Jul 2016 02:05 PM |
seems too little*
- Cinnace |
|
|
| Report Abuse |
|
|
iJava
|
  |
| Joined: 06 Mar 2011 |
| Total Posts: 29914 |
|
| |
|
iJava
|
  |
| Joined: 06 Mar 2011 |
| Total Posts: 29914 |
|
| |
|
Casualist
|
  |
| Joined: 26 Jun 2014 |
| Total Posts: 4443 |
|
|
| 05 Jul 2016 03:21 PM |
| This code isn't worth saving, probably best to scrap it and start over. |
|
|
| Report Abuse |
|
|
iJava
|
  |
| Joined: 06 Mar 2011 |
| Total Posts: 29914 |
|
|
| 05 Jul 2016 04:08 PM |
What's bad about it? This is the first time I've worked with welds, how can I improve it?
-Widths |
|
|
| Report Abuse |
|
|
| |
|
|
| 05 Jul 2016 05:29 PM |
Definitely fixed the bug with the colors. Think I fixed the other one, couldn't get it to happen any more.
repeat wait() until game.ReplicatedStorage:findFirstChild("Data") ~= nil repeat wait() until game.ReplicatedStorage.Data:findFirstChild(game.Players.LocalPlayer.Name) ~= nil repeat wait() until game.Players.LocalPlayer.Character ~= nil
math.randomseed(os.time()%16)
local plr = game.Players.LocalPlayer local chr = plr.Character local right = chr:findFirstChild("Right Arm") local left = chr:findFirstChild("Left Arm") local torso = chr:findFirstChild("Torso") local data = game.ReplicatedStorage.Data:findFirstChild(plr.Name) local inGame = data:findFirstChild("In_Game") local reloading = false
repeat wait() until inGame ~= nil
local container = workspace:FindFirstChild("LocalBin") if container == nil then container = Instance.new("Camera") container.Name = "LocalBin" container.Parent = workspace end local connections = {} function newConnection(func) table.insert(connections, func) end function disconnectAll() for i,v in pairs(connections) do v:disconnect() end connections = {} end function go() if inGame.Value then if(chr:findFirstChild("Left_Weld")) then return end repeat wait() plr.CameraMode = Enum.CameraMode.LockFirstPerson until plr.CameraMode == Enum.CameraMode.LockFirstPerson local fakeRight = right:clone() fakeRight.Parent = container table.insert(connections,right.Changed:connect(function(par) if(par == "BrickColor") then fakeRight.BrickColor = right.BrickColor end end)) local weld = Instance.new("Weld", chr) weld.Name = "Right_Weld" weld.Part0 = torso weld.Part1 = fakeRight local fakeLeft = left:clone() fakeLeft.Parent = container table.insert(connections,left.Changed:connect(function(par) if(par == "BrickColor") then fakeLeft.BrickColor = left.BrickColor end end)) local weld2 = Instance.new("Weld", chr) weld2.Name = "Left_Weld" weld2.Part0 = torso weld2.Part1 = fakeLeft fakeLeft.Material = Enum.Material.SmoothPlastic fakeRight.Material = Enum.Material.SmoothPlastic fakeLeft.TopSurface = Enum.SurfaceType.Smooth fakeLeft.BottomSurface = Enum.SurfaceType.Smooth fakeRight.TopSurface = Enum.SurfaceType.Smooth fakeRight.BottomSurface = Enum.SurfaceType.Smooth weld.C0 = weld.C0 * CFrame.Angles(math.rad(90),0,math.rad(-5)) weld.C1 = weld.C1 * CFrame.new(-1.25,-.5,.25) weld2.C0 = weld2.C0 * CFrame.Angles(math.rad(90),0,math.rad(20)) weld2.C1 = weld2.C1 * CFrame.new(0,.75,.1) local gun = script.Handle:clone() gun.Parent = container local weld3 = Instance.new("Weld", chr) weld3.Name = "Gun_Weld" weld3.Part0 = torso weld3.Part1 = gun weld3.C0 = weld3.C0 * CFrame.Angles(math.rad(90),math.rad(180),math.rad(5)) weld3.C1 = weld3.C1 * CFrame.new(1,1.75,-1) newConnection(game:GetService("RunService").RenderStepped:connect(function() --local transparency stuff end)) else disconnectAll() plr.CameraMode = Enum.CameraMode.Classic for i,v in pairs(container:GetChildren()) do v:Destroy() end for i,v in pairs(chr:GetChildren()) do if v:IsA("Weld") then v:Destroy() end end end end go() inGame.Changed:connect(function() print("Value changed") go() end) plr.CharacterAdded:connect(function() chr = plr.Character repeat wait() until (chr:findFirstChild("Right Arm") and chr:findFirstChild("Left Arm") and chr:findFirstChild("Torso")) right = chr:findFirstChild("Right Arm") left = chr:findFirstChild("Left Arm") torso = chr:findFirstChild("Torso") reloading = false print("going") go() end) function keyPress(input, event) if input.KeyCode == Enum.KeyCode.R and not reloading then --reload reloading = true local weld1 = chr:findFirstChild("Right_Weld") local weld2 = chr:findFirstChild("Left_Weld") local weld3 = chr:findFirstChild("Gun_Weld") coroutine.wrap(function() for i=1,3 do weld3.C0 = weld3.C0 * CFrame.Angles(math.rad(-5),0,0) weld1.C0 = weld1.C0 * CFrame.Angles(math.rad(5),0,0) wait(.01) end end)() wait(.01) coroutine.wrap(function() for i=1,5 do weld2.C0 = weld2.C0 * CFrame.Angles(0,0,math.rad(3)) wait(.01) end wait(.01) for i=1,25 do weld2.C0 = weld2.C0 * CFrame.Angles(math.rad(-1),0,0) wait(.01) end wait(.1) for i=1,25 do weld2.C0 = weld2.C0 * CFrame.Angles(math.rad(1),0,0) wait(.01) end for i=1,5 do weld2.C0 = weld2.C0 * CFrame.Angles(0,0,math.rad(-3)) wait(.01) end wait(.01) for i=1,3 do weld3.C0 = weld3.C0 * CFrame.Angles(math.rad(5),0,0) weld1.C0 = weld1.C0 * CFrame.Angles(math.rad(-5),0,0) wait(.01) end wait(.01) reloading = false end)() elseif input.KeyCode == Enum.KeyCode.O then plr.CameraMode = Enum.CameraMode.Classic end end game:GetService("UserInputService").InputBegan:connect(keyPress) |
|
|
| Report Abuse |
|
|
|
| 05 Jul 2016 05:50 PM |
| give this guy 1k he's earned it. |
|
|
| Report Abuse |
|
|
| |
|
iJava
|
  |
| Joined: 06 Mar 2011 |
| Total Posts: 29914 |
|
|
| 05 Jul 2016 06:16 PM |
Back, sorry. Your code fixes all the other bugs, however for some reason now if you die, you see your old arms. I replaced a part of your code and added this with no avail Fix the problem in your code and I'll give you the 1k, do you have a BC account?
plr.CharacterAdded:connect(function() chr = plr.Character repeat wait() until (chr:findFirstChild("Right Arm") and chr:findFirstChild("Left Arm") and chr:findFirstChild("Torso")) right = chr:findFirstChild("Right Arm") left = chr:findFirstChild("Left Arm") torso = chr:findFirstChild("Torso") reloading = false go() newConnection(chr.Humanoid.Died:connect(function() for i,v in pairs(container:GetChildren()) do v:Destroy() end for i,v in pairs(chr:GetChildren()) do if v:IsA("Weld") then v:Destroy() end end end)) end)
-Widths |
|
|
| Report Abuse |
|
|
| |
|
|
| 05 Jul 2016 06:47 PM |
| I mean, if you want a cleaner script, completely rewrite it, I do it all the time. |
|
|
| Report Abuse |
|
|
|
| 05 Jul 2016 06:49 PM |
https://www.roblox.com/my/item.aspx?id=167671505
Thanks :) Happy to help if you have other questions |
|
|
| Report Abuse |
|
|
|
| 05 Jul 2016 06:51 PM |
| I'm a little confused tho. I'm not getting the same problem as you. |
|
|
| Report Abuse |
|
|
iJava
|
  |
| Joined: 06 Mar 2011 |
| Total Posts: 29914 |
|
|
| 05 Jul 2016 06:51 PM |
@Mis Can you fix the glitch that makes it so you can still see your arms after dying?
-Widths |
|
|
| Report Abuse |
|
|
iJava
|
  |
| Joined: 06 Mar 2011 |
| Total Posts: 29914 |
|
|
| 05 Jul 2016 06:52 PM |
It only happens in an actual game, doesn't happen in studio
-Widths |
|
|
| Report Abuse |
|
|
|
| 05 Jul 2016 06:54 PM |
Nevermind got it.
repeat wait() until game.ReplicatedStorage:findFirstChild("Data") ~= nil repeat wait() until game.ReplicatedStorage.Data:findFirstChild(game.Players.LocalPlayer.Name) ~= nil repeat wait() until game.Players.LocalPlayer.Character ~= nil
math.randomseed(os.time()%16)
local plr = game.Players.LocalPlayer local chr = plr.Character local right = chr:findFirstChild("Right Arm") local left = chr:findFirstChild("Left Arm") local torso = chr:findFirstChild("Torso") local data = game.ReplicatedStorage.Data:findFirstChild(plr.Name) local inGame = data:findFirstChild("In_Game") local reloading = false
repeat wait() until inGame ~= nil
local container = workspace:FindFirstChild("LocalBin") if container == nil then container = Instance.new("Camera") container.Name = "LocalBin" container.Parent = workspace end local connections = {} function newConnection(func) table.insert(connections, func) end function disconnectAll() for i,v in pairs(connections) do v:disconnect() end connections = {} end function go() if inGame.Value then if(chr:findFirstChild("Left_Weld")) then return end repeat wait() plr.CameraMode = Enum.CameraMode.LockFirstPerson until plr.CameraMode == Enum.CameraMode.LockFirstPerson local fakeRight = right:clone() fakeRight.Parent = container table.insert(connections,right.Changed:connect(function(par) if(par == "BrickColor") then fakeRight.BrickColor = right.BrickColor end end)) local weld = Instance.new("Weld", chr) weld.Name = "Right_Weld" weld.Part0 = torso weld.Part1 = fakeRight local fakeLeft = left:clone() fakeLeft.Parent = container table.insert(connections,left.Changed:connect(function(par) if(par == "BrickColor") then fakeLeft.BrickColor = left.BrickColor end end)) local weld2 = Instance.new("Weld", chr) weld2.Name = "Left_Weld" weld2.Part0 = torso weld2.Part1 = fakeLeft fakeLeft.Material = Enum.Material.SmoothPlastic fakeRight.Material = Enum.Material.SmoothPlastic fakeLeft.TopSurface = Enum.SurfaceType.Smooth fakeLeft.BottomSurface = Enum.SurfaceType.Smooth fakeRight.TopSurface = Enum.SurfaceType.Smooth fakeRight.BottomSurface = Enum.SurfaceType.Smooth weld.C0 = weld.C0 * CFrame.Angles(math.rad(90),0,math.rad(-5)) weld.C1 = weld.C1 * CFrame.new(-1.25,-.5,.25) weld2.C0 = weld2.C0 * CFrame.Angles(math.rad(90),0,math.rad(20)) weld2.C1 = weld2.C1 * CFrame.new(0,.75,.1) --[[local gun = script.Handle:clone() gun.Parent = container local weld3 = Instance.new("Weld", chr) weld3.Name = "Gun_Weld" weld3.Part0 = torso weld3.Part1 = gun weld3.C0 = weld3.C0 * CFrame.Angles(math.rad(90),math.rad(180),math.rad(5)) weld3.C1 = weld3.C1 * CFrame.new(1,1.75,-1)]] newConnection(game:GetService("RunService").RenderStepped:connect(function() --local transparency stuff end)) else disconnectAll() plr.CameraMode = Enum.CameraMode.Classic for i,v in pairs(container:GetChildren()) do v:Destroy() end for i,v in pairs(chr:GetChildren()) do if v:IsA("Weld") then v:Destroy() end end end end go() inGame.Changed:connect(function() print("Value changed") go() end) plr.CharacterAdded:connect(function() chr = plr.Character repeat wait() until (chr:findFirstChild("Right Arm") and chr:findFirstChild("Left Arm") and chr:findFirstChild("Torso")) right = chr:findFirstChild("Right Arm") left = chr:findFirstChild("Left Arm") torso = chr:findFirstChild("Torso") reloading = false print("going") go() right.Transparency = 1 left.Transparency = 1 end) function keyPress(input, event) if input.KeyCode == Enum.KeyCode.R and not reloading then --reload reloading = true local weld1 = chr:findFirstChild("Right_Weld") local weld2 = chr:findFirstChild("Left_Weld") local weld3 = chr:findFirstChild("Gun_Weld") coroutine.wrap(function() for i=1,3 do weld3.C0 = weld3.C0 * CFrame.Angles(math.rad(-5),0,0) weld1.C0 = weld1.C0 * CFrame.Angles(math.rad(5),0,0) wait(.01) end end)() wait(.01) coroutine.wrap(function() for i=1,5 do weld2.C0 = weld2.C0 * CFrame.Angles(0,0,math.rad(3)) wait(.01) end wait(.01) for i=1,25 do weld2.C0 = weld2.C0 * CFrame.Angles(math.rad(-1),0,0) wait(.01) end wait(.1) for i=1,25 do weld2.C0 = weld2.C0 * CFrame.Angles(math.rad(1),0,0) wait(.01) end for i=1,5 do weld2.C0 = weld2.C0 * CFrame.Angles(0,0,math.rad(-3)) wait(.01) end wait(.01) for i=1,3 do weld3.C0 = weld3.C0 * CFrame.Angles(math.rad(5),0,0) weld1.C0 = weld1.C0 * CFrame.Angles(math.rad(-5),0,0) wait(.01) end wait(.01) reloading = false end)() elseif input.KeyCode == Enum.KeyCode.O then plr.CameraMode = Enum.CameraMode.Classic end end game:GetService("UserInputService").InputBegan:connect(keyPress) |
|
|
| Report Abuse |
|
|
iJava
|
  |
| Joined: 06 Mar 2011 |
| Total Posts: 29914 |
|
|
| 05 Jul 2016 06:55 PM |
would you mind telling me what to change in my script? I already changed almost all the CFraming welds so if I copy your code I'll have to fix it all again
thanks, also bought your shirt
-Widths |
|
|
| Report Abuse |
|
|
|
| 05 Jul 2016 06:56 PM |
| Oh yeah. Uncomment the stuff in go(). I didn't have your model so I just cut it out... |
|
|
| Report Abuse |
|
|
|
| 05 Jul 2016 06:56 PM |
This is the new characterAdded function
plr.CharacterAdded:connect(function() chr = plr.Character repeat wait() until (chr:findFirstChild("Right Arm") and chr:findFirstChild("Left Arm") and chr:findFirstChild("Torso")) right = chr:findFirstChild("Right Arm") left = chr:findFirstChild("Left Arm") torso = chr:findFirstChild("Torso") reloading = false print("going") go() right.Transparency = 1 left.Transparency = 1 end) |
|
|
| Report Abuse |
|
|
iJava
|
  |
| Joined: 06 Mar 2011 |
| Total Posts: 29914 |
|
|
| 05 Jul 2016 07:01 PM |
I need the fake arms transparent, not the actual arms I'm using the actual arms to render on the server with a different viewmodel
-Widths |
|
|
| Report Abuse |
|
|
|
| 05 Jul 2016 07:05 PM |
| So to clarify: real arms stay visible, fake arms go transparent when you die? |
|
|
| Report Abuse |
|
|