|
| 14 Aug 2013 08:13 AM |
SO I made this script to go in a HopperBin to make a sword but it is really glitchy and I don't know what the issue is.
repeat wait() until game.Players.LocalPlayer.Character ~= nil repeat wait() until game.Players.LocalPlayer ~= nil repeat wait() until game.Players.LocalPlayer.Stats ~= nil
Character = game.Players.LocalPlayer.Character Player = game.Players.LocalPlayer Stats = Player.Stats lastmove = nil hitenemy = false damage = 25 loaded = 1 --0 means the sword is actively being unequipped, 1 means the sword is ready to be equipped, 2 means the sword is loading, 3 means the sword is ready to swing, 4 means the sword is swinging script.Parent.Selected:connect(function(mouse) mouse.Icon = "rbxasset://textures\\GunCursor.png" mouse.Button1Down:connect(function() if loaded == 3 then loaded = 4 selectedmove = nil moves = {"attack1","attack2","attack3","attack4","attack5","attack6"} repeat selectedmove = moves [math.random(#moves)] until selectedmove ~= lastmove print(selectedmove) lastmove = selectedmove strikesound = Instance.new("Sound") strikesound.Parent = swordpart strikesound.SoundId = "http://www.roblox.com/asset/?id=45885030" if selectedmove == "attack1" then anim = Character.Humanoid:LoadAnimation(game.Lighting.Animations.attack1) anim:Play() wait(0.5) strikesound.Pitch = math.random(150,170)*0.01 strikesound:play() wait(0.3) elseif selectedmove == "attack2" then anim = Character.Humanoid:LoadAnimation(game.Lighting.Animations.attack2) anim:Play() swordweld.C0 = CFrame.new(0,-2.4,0) * CFrame.Angles(math.rad(0),math.rad(0),math.rad(180)) wait(0.5) strikesound.Pitch = math.random(150,170)*0.01 strikesound:play() wait(0.3) swordweld.C0 = CFrame.new(0,-1,-1.25) * CFrame.Angles(math.rad(0),math.rad(90),math.rad(-90)) elseif selectedmove == "attack3" then anim = Character.Humanoid:LoadAnimation(game.Lighting.Animations.attack3) anim:Play() wait(0.7) strikesound.Pitch = math.random(150,170)*0.01 strikesound:play() wait(0.1) elseif selectedmove == "attack4" then anim = Character.Humanoid:LoadAnimation(game.Lighting.Animations.attack4) anim:Play() wait(0.7) strikesound.Pitch = math.random(150,170)*0.01 strikesound:play() wait(0.1) elseif selectedmove == "attack5" then anim = Character.Humanoid:LoadAnimation(game.Lighting.Animations.attack5) anim:Play() wait(1) strikesound.Pitch = math.random(150,170)*0.01 strikesound:play() elseif selectedmove == "attack6" then anim = Character.Humanoid:LoadAnimation(game.Lighting.Animations.attack6) anim:Play() wait(0.25) strikesound.Pitch = math.random(150,170)*0.01 strikesound:play() wait(0.65) end strikesound:Destroy() if anim ~= nil then anim:Destroy() end loaded = 3 hitenemy = false end end) end)
function SelectedWeapon()
repeat wait() until game.Players.LocalPlayer.Character ~= nil repeat wait() until game.Players.LocalPlayer ~= nil repeat wait() until game.Players.LocalPlayer.Stats ~= nil
if loaded == 1 then else repeat wait() until loaded == 1 end loaded = 2 swordpart = Instance.new("Part") swordpart.Parent = game.Workspace.PlayerSwords swordpart.Name = Player.Name .. "'s Sword" swordpart.CanCollide = false swordpart.FormFactor = "Custom" swordpart.Size = Vector3.new(0.6,3.6,0.4) swordpart.TopSurface = "Smooth" swordpart.BottomSurface = "Smooth" swordmesh = Instance.new("SpecialMesh") swordmesh.MeshType = "FileMesh" swordmesh.MeshId = "http://www.roblox.com/asset/?id=94746028" swordmesh.TextureId = "http://www.roblox.com/asset/?id=94746105" swordmesh.Parent = swordpart swordweld = Instance.new("Weld") swordweld.Name = "swordweld" swordweld.Parent = Character:FindFirstChild("Right Arm") swordweld.Part0 = Character:FindFirstChild("Right Arm") swordweld.Part1 = swordpart swordweld.C0 = CFrame.new(0,-1,-1.25) * CFrame.Angles(math.rad(0),math.rad(90),math.rad(-90)) damagecoroutine = coroutine.create(function() swordpart.Touched:connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") ~= nil and game.Players:GetPlayerFromCharacter(hit.Parent).Name ~= hit.Parent.Name and hitenemy == false then hitenemy = true if game.Players:GetPlayerFromCharacter(hit.Parent).Stats.CurrentArmor.Value == "Clothes" then hit.Parent.Humanoid:TakeDamage(damage*1) elseif game.Players:GetPlayerFromCharacter(hit.Parent).Stats.CurrentArmor.Value == "Leather Armor" then hit.Parent.Humanoid:TakeDamage(damage*0.9) elseif game.Players:GetPlayerFromCharacter(hit.Parent).Stats.CurrentArmor.Value == "Steel Armor" then hit.Parent.Humanoid:TakeDamage(damage*0.75) elseif game.Players:GetPlayerFromCharacter(hit.Parent).Stats.CurrentArmor.Value == "Dark Armor" then hit.Parent.Humanoid:TakeDamage(damage*0.55) end end end) end) print("Check7") coroutine.resume(damagecoroutine) print("Check8") loaded = 3
end
function DeselectedWeapon()
print("Check9")
repeat wait() until game.Players.LocalPlayer.Character ~= nil repeat wait() until game.Players.LocalPlayer ~= nil repeat wait() until game.Players.LocalPlayer.Stats ~= nil
print("Check10")
if loaded == 2 or loaded == 3 or loaded == 4 then print("Check11") loaded = 0 if strikesound ~= nil then strikesound:Stop() strikesound:Destroy() end if anim ~= nil then anim:Stop() anim:Destroy() end if swordweld ~= nil then swordweld:Destroy() else repeat wait() until swordweld swordweld:Destroy() end swords = {game.Workspace.PlayerSwords:GetChildren()} for s = 1,#swords do if s.Name == Player.Name .. "'s Sword" then s:Destroy() end end loaded = 1 end end Character.Humanoid.Died:connect(DeselectedWeapon) script.Parent.Selected:connect(SelectedWeapon) script.Parent.Deselected:connect(DeselectedWeapon)
|
|
|
| Report Abuse |
|
|
Tkdriverx
|
  |
| Joined: 27 May 2008 |
| Total Posts: 235 |
|
|
| 14 Aug 2013 08:16 AM |
Try putting it in a LocalScript, first of all. Because it just won't work in a server in a regular script.
That's too much script to sift through.
~ Tkdriverx ~ |
|
|
| Report Abuse |
|
|
| |
|
Raphael7
|
  |
| Joined: 03 Dec 2008 |
| Total Posts: 2479 |
|
|
| 14 Aug 2013 08:54 AM |
Don't wait for Character that way, I've had some problems with that.
repeat wait() until game.Players.LocalPlayer -- This is what you should use.
> Trolls are radical hipsters. |
|
|
| Report Abuse |
|
|
| |
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 20 Aug 2013 12:18 AM |
"repeat wait() until game.Players.LocalPlayer.Stats ~= nil" Use findfirstchild first of all otherwise if it doesn't exist, you are erroring the script |
|
|
| Report Abuse |
|
|
|
| 20 Aug 2013 12:32 AM |
| Why does it matter which method I use? |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 20 Aug 2013 12:33 AM |
| Because if you don't use what I said, it will error the script. |
|
|
| Report Abuse |
|
|
|
| 20 Aug 2013 12:39 AM |
| Nothing showed up in the output. And everything exists. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 20 Aug 2013 12:39 AM |
| Then that line is useless, you may as well remove it |
|
|
| Report Abuse |
|
|
|
| 20 Aug 2013 12:40 AM |
| And even if I did use that, I would need to use the "repeat wait() until" in order to make the script wait until the thing exists. |
|
|
| Report Abuse |
|
|
|
| 20 Aug 2013 12:41 AM |
| If I removed it, then it would try to refference something that doesn't exist. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 20 Aug 2013 12:42 AM |
You are not understanding -.- If it didn't error, that means that line was run after it existed, making it useless.
Let's say I am waiting for a part to be created in Workspace repeat wait() until Game.Workspace.Part ^ If the part did not exist when this runs, the script will error
however: repeat wait() until Game.Workspace:FindFirstChild("Part") ^ This will not error and keep waiting till it finds the part. |
|
|
| Report Abuse |
|
|
|
| 20 Aug 2013 12:49 AM |
| Okay then tell me how I would replace the first 7 lines in order to set those variables if I were you. |
|
|
| Report Abuse |
|
|
|
| 20 Aug 2013 12:49 AM |
| Also I have those line there to make sure it doesn't error. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 20 Aug 2013 12:51 AM |
This is what I would do:
repeat wait() until game.Players.LocalPlayer and game.Players.LocalPlayer.Character
Player = game.Players.LocalPlayer Character = Player.Character Stats = Player:WaitForChild("Stats") |
|
|
| Report Abuse |
|
|
|
| 20 Aug 2013 12:54 AM |
| That's pretty much the exact same thing. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 20 Aug 2013 12:57 AM |
| Except more efficient and less lines and cleaner code. |
|
|
| Report Abuse |
|
|
|
| 20 Aug 2013 01:08 AM |
| Okay, so. It isn't what's wrong with the script. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 20 Aug 2013 01:09 AM |
No c: Your way __may__ have caused errors, but didn't. So something else is wrong. |
|
|
| Report Abuse |
|
|
|
| 20 Aug 2013 01:12 AM |
| Yeah, I think so. But i did manage to shorten the script by a couple lines. |
|
|
| Report Abuse |
|
|
|
| 20 Aug 2013 02:28 AM |
| Okay, I got that shortened but I still need to fix it. |
|
|
| Report Abuse |
|
|
Quaken
|
  |
| Joined: 31 Aug 2008 |
| Total Posts: 421 |
|
| |
|
Quaken
|
  |
| Joined: 31 Aug 2008 |
| Total Posts: 421 |
|
| |
|
Quaken
|
  |
| Joined: 31 Aug 2008 |
| Total Posts: 421 |
|
| |
|