Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Problem with my Gun Effect script?

Asked by 10 years ago

I am making some effects for a gun, and the script i've attempted to create is supposed to create a forcefeild around the player on a key down toggle. i think possibly the weld could have gone wrong. I'm not sure.. Anyone got suggestions/ ideas why?

forcefeild=script.Parent.Forcefeild
 torso=script.Parent.Parent.Torso

local tool=script.Parent
tool.Equipped:connect(function(mouse)
    mouse.KeyDown:connect(function(key)
if key == "f" then
forcefeild.Script2.Disabled=false 

forcefeild.Anrchored=true
   local weld1 = Instance.new("Weld") 
 weld1.Parent=torso
 weld1.Part0=torso
   weld1.Part1 = forcefeild
 forcefeild.Anrchored=false

local i = 1
while( i > 6) do
forcefeild.Size = i,i,i
wait(.1)
i = i - 1
end
  elseif key=="f" then 
forcefeild.Script2.Disabled=true
local i = 6
while( i < 0) do
forcefeild.Size = i,i,i
wait(.1)
i = i + 1
end
end
  end)
end)

1 answer

Log in to vote
1
Answered by
Muoshuu 580 Moderation Voter
10 years ago

No offense, but you made a lot of errors and spelling mistakes.

First of all, you tried to make an else-if statement that has two of the exact same statements, basically if Key=="f" then elseif Key=="f" then end. Next you misspelled Forcefield multiple times (Dependent upon your variable name) Next, you never removed the weld when removing the forcefield. You also never changed the parent (I'm assuming this 'Forcefield' is a Part). Another thing, if you were to press F while it was resizing, it'd screw it up, I fixed that in the code below. Also, if you have a Part in a Tool, it will always show up in the workspace if the person has the tool equipped. I made it so it automatically parents it to ReplicatedStorage.

Code:

local Forcefield=script.Parent.Forcefield
Forcefield.Parent=game.ReplicatedStorage
local Torso=script.Parent.Parent.Torso
local Tool=script.Parent
local Enabled=false
local Resizing=false
local Weld

Tool.Equipped:connect(function(Mouse)
    Tool.KeyDown:connect(function(Key)
        if Resizing then return end
        Key=Key:lower()
        if Key=="f" then
            if not Enabled then
                Resizing=true
                Forcefield.Script2.Disabled=false
                Forcefield.Anchored=true
                Forcefield.Parent=script.Parent
                Weld=Instance.new("Weld",Torso)
                Weld.Part0=Torso
                Weld.Part1=Forcefield
                Forcefield.Anchored=false
                for i=1,6 do
                    Forcefield.Size=Vector3.new(i,i,i)
                    wait(.1)
                end
                Resizing=false
                Enabled=true
            elseif Enabled then
                Resizing=true
                Forcefield.Script2.Disabled=true
                for i=6,1,-1 do
                    Forcefield.Size=Vector3.new(i,i,i)
                    wait(.1)
                end
                Weld:destroy()
                Forcefield.Parent=game.ReplicatedStorage
                Resizing=false
                Enabled=true
            end
        end
    end)
end)
Ad

Answer this question