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: Local script. Tool. Wont work Right.

Previous Thread :: Next Thread 
kingmatt2 is not online. kingmatt2
Joined: 20 Aug 2011
Total Posts: 6494
07 Mar 2013 07:20 PM
This is just a fration of the script. It works 100%, But not how I want it.

Its a crouch script

Its at the end of the script.

Its spose to work when you have tool out.
But it works when you have the tool out, and when you dont.
I jsut want it to work when you have the tool out

Ask me for any more questions.

----The Fraction Of The Script----


local mouse = script.Parent.Parent.Parent:GetMouse()
mouse.Button1Down:connect(function()
if (on==1) then
on=0
elseif (on==0) then
on=1
end
Crouch(on)
end)




Report Abuse
1Topcop is not online. 1Topcop
Joined: 09 Jun 2009
Total Posts: 6635
07 Mar 2013 07:31 PM
If you only want it to work when a tool is selected, why not use the Equipped event?

wait()
Tool.Equipped:connect(function(mouse)
mouse.Button1Down:connect(function()
on = on==1 and 0 or 1
Crouch(on)
end)end)
Report Abuse
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
07 Mar 2013 07:33 PM
...

Assuming the script's parent is the Tool:

local selected = false

script.Parent.Equipped:connect(function(mouse)
selected = true
mouse.Button1Down:connect(function()
if selected then
if (on==1) then
on=0
elseif (on==0) then
on=1
end
Crouch(on)
end
end)
end)

script.Parent.Unequipped:connect(function()
selected = false
end)

ElectricBlaze • Programmer • Wiki Writer | http://wiki.roblox.com/index.php/User:ElectricBlaze
Report Abuse
kingmatt2 is not online. kingmatt2
Joined: 20 Aug 2011
Total Posts: 6494
07 Mar 2013 07:34 PM
That dident work, Sorry...
Report Abuse
kingmatt2 is not online. kingmatt2
Joined: 20 Aug 2011
Total Posts: 6494
07 Mar 2013 07:34 PM
wait im testing eletics now... That was for the guy before
Report Abuse
1Topcop is not online. 1Topcop
Joined: 09 Jun 2009
Total Posts: 6635
07 Mar 2013 07:35 PM
@Blaze I'm pretty sure the Button1Down event is disconnected/won't fire when Unequipped is called. :P
Report Abuse
kingmatt2 is not online. kingmatt2
Joined: 20 Aug 2011
Total Posts: 6494
07 Mar 2013 07:35 PM
Still dident work for eather of your scritps. Sorry.
Report Abuse
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
07 Mar 2013 07:35 PM
@1Topcop - I'm pretty sure you're right, but I'm not taking any chances for this guy. He's been trying to solve this for quite a while.

ElectricBlaze • Programmer • Wiki Writer | http://wiki.roblox.com/index.php/User:ElectricBlaze
Report Abuse
1Topcop is not online. 1Topcop
Joined: 09 Jun 2009
Total Posts: 6635
07 Mar 2013 07:36 PM
Is the first line of code executed "wait()"? All LocalScripts need a wait at the very top before any code runs.
Report Abuse
kingmatt2 is not online. kingmatt2
Joined: 20 Aug 2011
Total Posts: 6494
07 Mar 2013 07:37 PM
Make sure you read all of the top. This fraction of the script is at the very bottom.
Report Abuse
1Topcop is not online. 1Topcop
Joined: 09 Jun 2009
Total Posts: 6635
07 Mar 2013 07:37 PM
@Blaze how long he been tryin? o:
(Also, maybe think maybe you tell the Wiki administrators to let me be wiki writer, maybe? ;3)
Report Abuse
kingmatt2 is not online. kingmatt2
Joined: 20 Aug 2011
Total Posts: 6494
07 Mar 2013 07:38 PM
an hour or two.
Report Abuse
1Topcop is not online. 1Topcop
Joined: 09 Jun 2009
Total Posts: 6635
07 Mar 2013 07:38 PM
@Matt how long is the code? If it's less then say.. 200 lines, maybe post it?
Report Abuse
MassiveGman is not online. MassiveGman
Joined: 23 Jan 2011
Total Posts: 2019
07 Mar 2013 07:39 PM
GetMouse can get the mouse without the tool out. :GetMouse() is used for scripts to access the player's input even when the player does not have a tool equipped. Such method allows run/walk scripts from pressing shift, with no tool in the inventory.


-[MassiveGman]
Report Abuse
kingmatt2 is not online. kingmatt2
Joined: 20 Aug 2011
Total Posts: 6494
07 Mar 2013 07:39 PM
Its like 80.... Here it is, If It will help.




--The script--










wait()
on = 0
game.Players.LocalPlayer.CharacterAdded:wait()
repeat wait() until game.Players.LocalPlayer.Character:findFirstChild("Torso")
Tool = game.Players.LocalPlayer.Character.Torso;
welds = {}
sh = {}
arms = nil
torso = nil
f = nil
function Crouch(ison)
if arms == nil and torso == nil then
arms = {Tool.Parent:FindFirstChild("Left Leg"), Tool.Parent:FindFirstChild("Right Leg")}
torso = Tool.Parent:FindFirstChild("Torso")
end
if arms ~= nil and torso ~= nil then
sh = {torso:FindFirstChild("Left Hip"), torso:FindFirstChild("Right Hip")}
if sh ~= nil then
local yes = true
if yes then
yes = false
if ison == 1 then
sh[1].Part1 = nil
sh[2].Part1 = nil
local weld1 = Instance.new("Weld")
weld1.Part0 = torso
weld1.Parent = torso
weld1.Part1 = arms[1]
weld1.C1 = CFrame.new(-0.5, 0.75, 1)
arms[1].Name = "LDave"
arms[1].CanCollide = true
welds[1] = weld1
-------------------------------------------
local weld2 = Instance.new("Weld")
weld2.Part0 = torso
weld2.Parent = torso
weld2.Part1 = arms[2]
weld2.C1 = CFrame.new(0.5,0.495,1.25) * CFrame.fromEulerAnglesXYZ(math.rad(90),0,0)
arms[2].Name = "RDave"
arms[2].CanCollide = true
welds[2] = weld2
---------------------------------
local force = Instance.new("BodyForce")
force.Parent = torso
f = force
wait(0.01)
elseif ison == 0 then
if arms then
sh[1].Part1 = arms[1]
sh[2].Part1 = arms[2]
f.Parent = nil
arms[2].Name = "Right Leg"
arms[1].Name = "Left Leg"
welds[1].Parent = nil
welds[2].Parent = nil
end
end
--
end
else
print("sh")
end
else
print("arms")
end
end

local selected = false

script.Parent.Equipped:connect(function(mouse)
selected = true
mouse.Button1Down:connect(function()
if selected then
if (on==1) then
on=0
elseif (on==0) then
on=1
end
Crouch(on)
end
end)
end)

script.Parent.Unequipped:connect(function()
selected = false
end)
Report Abuse
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
07 Mar 2013 07:40 PM
@1Topcop - lol

Go to gordonrox24's profile. It contains a link to the survey you have to fill out in order to become a wiki writer.

ElectricBlaze • Programmer • Wiki Writer | http://wiki.roblox.com/index.php/User:ElectricBlaze
Report Abuse
IJustPwndYou is not online. IJustPwndYou
Joined: 06 Mar 2012
Total Posts: 985
07 Mar 2013 07:44 PM
>All LocalScripts need a wait at the very top before any code runs.

That's untrue.
Report Abuse
kingmatt2 is not online. kingmatt2
Joined: 20 Aug 2011
Total Posts: 6494
07 Mar 2013 07:44 PM
It is unture. The script works fine, It just doesent woek how I want it.
Report Abuse
kingmatt2 is not online. kingmatt2
Joined: 20 Aug 2011
Total Posts: 6494
07 Mar 2013 07:48 PM
So... Is anyone going to help me? Unless your trying to figure out how to help. Than why are you on this fourm? Or scripting helpers?
Report Abuse
1Topcop is not online. 1Topcop
Joined: 09 Jun 2009
Total Posts: 6635
07 Mar 2013 07:48 PM
-- Inside a LocalScript in a HopperBin
wait()
on = false
local Player = game.Players.LocalPlayer
repeat wait() until Player.Character
c = Player.Character
Tool = script.Parent
welds = {}
sh = {}
arms = nil
f = nil
function Crouch()
torso = c:FindFirstChild("Torso")
arms = {c:FindFirstChild("Left Leg"),c:FindFirstChild("Right Leg")}
sh = {torso:FindFirstChild("Left Hip"), torso:FindFirstChild("Right Hip")}
if sh[1] and sh[2] and arms[1] and arms[2] and torso then
if on then
sh[1].Part1 = nil
sh[2].Part1 = nil
local weld1 = Instance.new("Weld",torso)
weld1.Part0 = torso
weld1.Part1 = arms[1]
weld1.C1 = CFrame.new(-0.5, 0.75, 1)
arms[1].Name = "LDave"
arms[1].CanCollide = true
welds[1] = weld1
-------------------------------------------
local weld2 = Instance.new("Weld")
weld2.Part0 = torso
weld2.Parent = torso
weld2.Part1 = arms[2]
weld2.C1 = CFrame.new(0.5,0.495,1.25) * CFrame.fromEulerAnglesXYZ(math.rad(90),0,0)
arms[2].Name = "RDave"
arms[2].CanCollide = true
welds[2] = weld2
---------------------------------
local force = Instance.new("BodyForce")
force.Parent = torso
f = force
wait(0.01)
else
sh[1].Part1 = arms[1]
sh[2].Part1 = arms[2]
f.Parent = nil
arms[2].Name = "Right Leg"
arms[1].Name = "Left Leg"
welds[1].Parent = nil
welds[2].Parent = nil
end
end
end


Tool.Selected:connect(function(mouse)
mouse.Button1Down:connect(function()
on = not on
Crouch()
end)
end)
Report Abuse
kingmatt2 is not online. kingmatt2
Joined: 20 Aug 2011
Total Posts: 6494
07 Mar 2013 07:49 PM
THANK YOU. Testing now. Thanks for makeing an intire new script.
Report Abuse
1Topcop is not online. 1Topcop
Joined: 09 Jun 2009
Total Posts: 6635
07 Mar 2013 07:50 PM
No, in fact you do need a wait at the very top of all LocalScripts, or sometimes without warning in online mode, the code will not run.
Report Abuse
kingmatt2 is not online. kingmatt2
Joined: 20 Aug 2011
Total Posts: 6494
07 Mar 2013 07:50 PM
... Aw man.. That dident work.
Report Abuse
1Topcop is not online. 1Topcop
Joined: 09 Jun 2009
Total Posts: 6635
07 Mar 2013 07:51 PM
@Matt, it's not ENTIRELY new, I just edited around some things :P
There's also a couple extra variables at the top that I forgot to remove, but w/e, the script should still work.
Report Abuse
1Topcop is not online. 1Topcop
Joined: 09 Jun 2009
Total Posts: 6635
07 Mar 2013 07:54 PM
-- Try this
wait()
on = false
local Player = game.Players.LocalPlayer
repeat wait() until Player.Character
c = Player.Character
Tool = script.Parent
welds = {}
function Crouch()
torso = c:FindFirstChild("Torso")
arms = {c:FindFirstChild("Left Leg"),c:FindFirstChild("Right Leg")}
sh = {torso:FindFirstChild("Left Hip"), torso:FindFirstChild("Right Hip")}
if sh[1] and sh[2] and arms[1] and arms[2] and torso then
if on then
sh[1].Part1 = nil
sh[2].Part1 = nil
local weld1 = Instance.new("Weld",torso)
weld1.Part0 = torso
weld1.Part1 = arms[1]
weld1.C1 = CFrame.new(-0.5, 0.75, 1)
arms[1].Name = "LDave"
arms[1].CanCollide = true
welds[1] = weld1
-------------------------------------------
local weld2 = Instance.new("Weld",torso)
weld2.Part0 = torso
weld2.Part1 = arms[2]
weld2.C1 = CFrame.new(0.5,0.495,1.25) * CFrame.fromEulerAnglesXYZ(math.rad(90),0,0)
arms[2].Name = "RDave"
arms[2].CanCollide = true
welds[2] = weld2
---------------------------------
local force = Instance.new("BodyForce")
force.Parent = torso
f = force
wait()
elseif(f)then
sh[1].Part1 = arms[1]
sh[2].Part1 = arms[2]
f.Parent = nil
arms[2].Name = "Right Leg"
arms[1].Name = "Left Leg"
welds[1].Parent = nil
welds[2].Parent = nil
end
end
end


Tool.Selected:connect(function(mouse)
mouse.Button1Down:connect(function()
on = not on
Crouch()
end)
end)
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