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

How do i detect and make a variable for a player that clickes?

So I am trying to make a fishing simulator game, but I need the line that gets created between the water and the rod, but I am stuck at the line from the player's rod, I could only make it so that the line appears between a specific player name, can anyone help me, please. Here is my code:

local tool = game.Players.Anderssc.Backpack.rod

local starterRod = game.Players:WaitForChild()

tool.Activated:Connect(function()
	
	local Rope = Instance.new("RopeConstraint", workspace)
	Rope.Attachment0 = starterRod.Attachment0
	Rope.Attachment1 = game.Workspace.Rope2.Attachment1
	Rope.Visible = true	
	
end)

1 answer

✓ Accepted answer

Instead of checking for a player outside of the tool, I would put this script in the tool so you wouldn't have to check the player's backpack. I would also put the RodConstraint in the starterRod and not the workspace (For organization). The code should be somewhere along the lines of this:

local tool = script.Parent

local starterRod = game.Players:WaitForChild("starterRod") -- Change "starterRod" to whatever the thing you're waiting for's name

tool.Activated:Connect(function()

	local Rope = Instance.new("RopeConstraint", starterRod)
	Rope.Attachment0 = starterRod.Attachment0
	Rope.Attachment1 = game.Workspace.Rope2.Attachment1
	Rope.Visible = true 

end)

Hope I helped! If you've got any questions on anything, just ask me in the comments.

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