Alright so I’m trying to make a script for when a player clicks a part.
The expected result should be the script creates a RopeConstraint in the players left hand and an attachment in both the players hand an the clicked part.
However, my issue is that the rope isn’t created between the player and part, and no error is given.
Its most likely a basic issue but I’ve not done script in a while.
Thank you!
Script:
function onClicked()
local Players = game:GetService("Players")
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(c)
local Rope = Instance.new("RopeConstraint")
Rope.Parent = script.Parent
local At1 = Instance.new("Attachment")
local At2 = Instance.new("Attachment")
At1.Parent = script.Parent
At2.Parent = player.Character.LeftHand
At1.Name = "Attachment0"
At2.Name = "Attachment1"
Rope.Attachment0 = game.Workspace.Rock.Attachment0
Rope.Attachment1 = player.Character.LeftHand.Attachment1
Rope.Length = 7
Rope.Visible = true
end)
end)
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)
I’m not sure of what you want to happen to the player that clicks the button. Do you want the player that clicks the button to be connected to the rock right? sorry I’m not sure.
I noticed a few flaws within your code so I hopped into studio and refactored it a bit. After testing it I got it to work for me. I tried commenting out the things I changed to make it easier for you. I hope this works out for you!
function onClicked(player) -- MouseClick is fired with the player who clicked
local char = player.Character or player.CharacterAdded:Wait() -- Get the player character
local Rope = Instance.new("RopeConstraint")
Rope.Parent = script.Parent
local At1 = Instance.new("Attachment")
local At2 = Instance.new("Attachment")
At1.Parent = script.Parent
At2.Parent = char.LeftHand
At1.Name = "Attachment0"
At2.Name = "Attachment1"
Rope.Attachment0 = At1 -- You might wanna change this to what it was before
Rope.Attachment1 = At2 -- You might wanna change this to what it was before
Rope.Length = 7
Rope.Visible = true
end
script.Parent.ClickDetector.MouseClick:Connect(onClicked) -- Changed this to use Connect since connect is deprecated