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

I can only shoot a rope once but cant shoot it again, why? [SOLVED]

Asked by 6 years ago
Edited 6 years ago

I have a script of a grapple hook thingy.. that shoots rope constraint and you can use it to swing. I want to do some kind of lava level where you need to swing above the lava without dying (falling). But for some reason when I shoot the rope, it shoots it only ONCE.. and I cant shoot it again.

I placed the code inside LocalScript and placed it inside StarterCharacterScripts.

Oh and also, when I was in the game I tried to delete the script inside my character and put it back in, and I could shoot the rope again. I thought of making a script that gives me a new one and deletes the old one, I dont really know how to do it. I wanted to know if there is an "easier" fix to this problem.

01--// Variables:
02 
03local plr = game.Players.LocalPlayer
04local char = plr.Character
05local head = char:FindFirstChild("Head")
06 
07local athA = Instance.new("Attachment", head)
08local athPart = game.Workspace.AttachPart
09local athB = Instance.new("Attachment", athPart)
10athA.Position = Vector3.new(0,0,-1)
11local rope = Instance.new("RopeConstraint", head)
12local length = (head.Position - athPart.Position).magnitude
13local uis = game:GetService("UserInputService")
14isSwinging = false
15 
View all 40 lines...

https://vimeo.com/user90972315/review/297152618/40319cd20c

Video of me showing how I am removing and adding back the script, and it works.

Found the solution, I removed the lines that destroy the attachments

1
Do you have a debounce of when you can shoot or not? Life if you are loaded and when you are unloaded. Stephenthefox 94 — 6y
1
I mean, I made the "isSwinging".. I dont know if its correct tho and if it works. Is is good? HeyItzDanniee 252 — 6y
0
I got it. User#21908 42 — 6y
0
The length also needs set every time. User#21908 42 — 6y
View all comments (2 more)
0
I edited my answer, take a look. User#21908 42 — 6y
0
I already fixed it. Your code doesnt work, you should leave the attachments and not destroy them. Thank you anyways for trying when nobody else really did besides a few. :) HeyItzDanniee 252 — 6y

2 answers

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

The issue is that you are destroying the rope you made. The simple answer is to just create a new rope every time the player hits r. Example with comment explanation:

01local players = game:GetService("Players") -- this is the recommended way to get the players service
02local plr = players.LocalPlayer
03 
04local char = plr.Character
05local head = char:FindFirstChild("Head")
06 
07local athA = Instance.new("Attachment") -- the second parameter to Instance.new() is deprecated. Set the parent later after all the properties have been changed to your liking.
08local athPart = game.Workspace.AttachPart
09local athB = Instance.new("Attachment")
10athB.Parent = athPart
11athA.Position = Vector3.new(0,0,-1)
12athA.Parent = head
13local rope -- we will define this later
14local length -- also define this later
15local uis = game:GetService("UserInputService")
View all 45 lines...

I hope this helps and have a great day scripting! Edit: I changed where the length is defined as well. If this code still does not work, then the issue is with your variable logic and how you are using the different properties. I cannot help you beyond this because I don't know what your game and workspace look like.

0
Doesn`t works :C still same problem, I can only shoot once. HeyItzDanniee 252 — 6y
Ad
Log in to vote
-2
Answered by 6 years ago

Dude, you made a common mistake alot of people make. Whenever you destroy a object, or delete a object in your code, make sure to add it back. You destroyed the rope inside your code so when you launch the rope, there is no rope to launch. You destroy the rope here: (Line 36)

1if key.KeyCode == Enum.KeyCode.R then
2 
3    if isSwinging == true then
4 
5        rope.Attachment0:Destroy()
6 
7        rope.Attachment1:Destroy()
8 
9        rope:Destroy()

Either need to create a new rope in 'InputBegan' event or not destroy to rope in general and temporarily remove the attachment points.

Please accept this responce, i need to get rep to 100 again to talk in forum again cause moderators dont trust me. -.-

0
You don't always need to add something you destroyed back. User#21908 42 — 6y

Answer this question