Plutoeros
|
  |
| Joined: 13 Feb 2016 |
| Total Posts: 214 |
|
|
| 09 Jul 2017 02:01 PM |
As it says in the title, I tried creating a script which sets out on the task of when the GUIButton is held down (pressed down) the player would continue to jump and when it's let go, the player would stop jumping. The example of the script I've devised is shown below, but I have a feeling I'm doing something wrong:
local player = game.Players.LocalPlayer local buttonHeld = false
script.Parent.MouseButton1Down:connect(function() if script.Parent.MouseButton1Down then buttonHeld = true while buttonHeld do player.Character.Humanoid.Jump = true wait() end end script.Parent.MouseButton1Up:connect(function() if script.Parent.MouseButton1Down then buttonHeld = false end end
- VIShark15 |
|
|
| Report Abuse |
|
|
BaiYuni
|
  |
| Joined: 09 Oct 2009 |
| Total Posts: 2861 |
|
|
| 09 Jul 2017 02:07 PM |
local player = game.Players.LocalPlayer local character = player.Character local humanoid = character.Humanoid
local isJumping = true script.Parent.TextButton.MouseButton1Down:connect(function () isJumping = true while isJumping do humanoid.Jump = true wait() end end)
script.Parent.TextButton.MouseButton1Up:connect(function () isJumping = false end) |
|
|
| Report Abuse |
|
|
BaiYuni
|
  |
| Joined: 09 Oct 2009 |
| Total Posts: 2861 |
|
|
| 09 Jul 2017 02:09 PM |
Oops, I just replicated it to my own.
local player = game.Players.LocalPlayer local buttonHeld = false
script.Parent.MouseButton1Down:connect(function() buttonHeld = true while buttonHeld do player.Character.Humanoid.Jump = true wait() end end script.Parent.MouseButton1Up:connect(function() buttonHeld = false end
|
|
|
| Report Abuse |
|
|
Plutoeros
|
  |
| Joined: 13 Feb 2016 |
| Total Posts: 214 |
|
|
| 09 Jul 2017 02:09 PM |
Thanks a lot, now I can do the same for direction keys :D
- VIShark15 |
|
|
| Report Abuse |
|
|
Plutoeros
|
  |
| Joined: 13 Feb 2016 |
| Total Posts: 214 |
|
|
| 09 Jul 2017 03:07 PM |
Sorry to disrupt you again, but as soon as the player dies, the script just goes away completely, I attempted to do some revision to the script but it ended up not working at all :/
game.Players.PlayerAdded:Connect(function(newPlayer) newPlayer.CharacterAdded:Connect(function(newCharacter) local character = newCharacter.character local humanoid = character.Humanoid
local isJumping = true
script.Parent.MouseButton1Down:connect(function() isJumping = true while isJumping do humanoid.Jump = true wait() end end)
script.Parent.MouseButton1Up:connect(function() isJumping = false end)
- VIShark15 |
|
|
| Report Abuse |
|
|
BaiYuni
|
  |
| Joined: 09 Oct 2009 |
| Total Posts: 2861 |
|
| |
|
Plutoeros
|
  |
| Joined: 13 Feb 2016 |
| Total Posts: 214 |
|
|
| 09 Jul 2017 03:14 PM |
Yeah, contained within the ImageButton (also, I tried duplicating the past script to adjust to the player moving forward and backwards within other buttons, but all of them stopped working).
- VIShark15 |
|
|
| Report Abuse |
|
|
BaiYuni
|
  |
| Joined: 09 Oct 2009 |
| Total Posts: 2861 |
|
|
| 09 Jul 2017 03:17 PM |
| Once the player dies? What is the error though? |
|
|
| Report Abuse |
|
|
Plutoeros
|
  |
| Joined: 13 Feb 2016 |
| Total Posts: 214 |
|
|
| 09 Jul 2017 03:19 PM |
There is no visual error, the jump button literally just stops working, I'll test again to make sure I haven't missed anything out.
- VIShark15 |
|
|
| Report Abuse |
|
|
Plutoeros
|
  |
| Joined: 13 Feb 2016 |
| Total Posts: 214 |
|
|
| 09 Jul 2017 03:23 PM |
Oh, it works now, sorry for disrupting you for a pointless 10 minutes ;-;. But if you don't mind, how would this script be integrated so that instead of jumping, it moves the player either forwards or backwards? I tried Vector3, but that only goes the direction of the camera, which wasn't what I needed. Thanks for all of the help, it's honestly, appreciated :)
- VIShark15 |
|
|
| Report Abuse |
|
|
BaiYuni
|
  |
| Joined: 09 Oct 2009 |
| Total Posts: 2861 |
|
| |
|
Plutoeros
|
  |
| Joined: 13 Feb 2016 |
| Total Posts: 214 |
|
|
| 09 Jul 2017 03:37 PM |
I tried doing this (basically a pure copy of the jumping script thingy) but the player doesn't move at all, the jumping still works in conjunction thankfully!
player.Character.Humanoid:MoveTo(0,0,16)
I placed this where 'player.Character.Humanoid.Jump = true' was, is this the correct usage of MoveTo?
- VIShark15 |
|
|
| Report Abuse |
|
|
BaiYuni
|
  |
| Joined: 09 Oct 2009 |
| Total Posts: 2861 |
|
|
| 09 Jul 2017 03:37 PM |
| I believe you'd have to add the ################### ######### ## ###### for it to work. |
|
|
| Report Abuse |
|
|
BaiYuni
|
  |
| Joined: 09 Oct 2009 |
| Total Posts: 2861 |
|
|
| 09 Jul 2017 03:39 PM |
Add 2nd param
of the function |
|
|
| Report Abuse |
|
|
Plutoeros
|
  |
| Joined: 13 Feb 2016 |
| Total Posts: 214 |
|
|
| 09 Jul 2017 03:52 PM |
Okay think I made some progress, the game now crashes when I click on the button to run the script. I hope this is what you mean by second parameter:
player.Character.Humanoid:MoveTo(Vector3.new(0,0,16), true)
- VIShark15 |
|
|
| Report Abuse |
|
|
BaiYuni
|
  |
| Joined: 09 Oct 2009 |
| Total Posts: 2861 |
|
|
| 09 Jul 2017 04:06 PM |
| I think the 2nd param is suppose to be an object, like a platform. |
|
|
| Report Abuse |
|
|
Plutoeros
|
  |
| Joined: 13 Feb 2016 |
| Total Posts: 214 |
|
|
| 09 Jul 2017 04:23 PM |
Tried making a block at the end of the baseplate named 'Finish' and put this in the localscript:
local player = game.Players.LocalPlayer local buttonHeld = false
script.Parent.MouseButton1Down:connect(function() buttonHeld = true while buttonHeld do player.Character.Humanoid:MoveTo(Vector3.new(0,0,16), game.Workspace.Part.Finish) end end)
script.Parent.MouseButton1Up:connect(function() buttonHeld = false end)
This should work right, or am I still doing something wrong?
- VIShark15 |
|
|
| Report Abuse |
|
|