Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

My rope constraint isn't spawning. Can someone help me?

I'm trying to make a script where a rope is binded to the player so that they can swing on specific points. I assumed that it was easy to make constraints via script because then you can enable and disable the script based on which points you're on.

local attachmentA = Instance.new("Attachment")
attachmentA.Parent = game.Workspace.Constrainer

local attachmentB = Instance.new("Attachment")
attachmentB.Parent = game.Players.LocalPlayer.Character.UpperTorso

local ropeConstraint = Instance.new("RopeConstraint")
	ropeConstraint.Length = 10
	ropeConstraint.Parent = game.Workspace.Constrainer
	ropeConstraint.Attachment0 = attachmentA
	ropeConstraint.Attachment1 = attachmentB

ropeConstraint.Enabled = true

Despite this script, a rope constraint isn't spawning yet the attachment is.

4 comments

0

Both attachments are spawning? There's probably an error

0

There's an error in the output that says attempt to index nil with Character. The reason could possibly be due to the fact that this is a server script and not a local script, so localplayer might not be able to be seen.

0

I'm testing it.

0

yeah change this script to a local script and insert it into StarterPack and it should work! :)

1 answer

✓ Accepted answer

When you have an error that says something is nil it simply means it cant find it because it doesnt exist.

Scripts run faster than the time it takes for your game to load.. Try adding this:

local player = game.Players.LocalPlayer
local character = player.CharacterAdded:Wait() --This will tell the script to wait untill the character loads. When it does it sets the value of the character.

After your character loaded, your character variable shouldnt give you an error.

By the way, I have made a swinging script before and I advice you to connect the rope to the HumanoidRootPart When I connected it to either the hand or the torso part, the character gets stuck and wont move.

Im not sure if that thing still happens but if your character gets stuck just know this is the fix for that, took me couple of months to figure that out tho lol but at least I did.

This discussion is preserved as it was. New answers, comments, and votes are closed.