How to find a player's script in the workspace

Hello everybody!
I faced the problem that I don’t know how to make the script find the player in the workspace.
The script should do a simple thing, glue a small stick to the player’s hand, but this stick should not be a tool.

game.Players.PlayerAdded:Connect(function(player)
	repeat wait() until player and player.Character
	wait(5)
	local SharpeningUpgrdScript = require(game.ReplicatedStorage.sharpening.sharpening)	
	local SharpeningUpgrd = player.Tools.SharpeningUpgrd.Value
	local ReplicatedStorage = game:GetService("ReplicatedStorage")
		
	local ToolSharpening = ReplicatedStorage.SharpeningTool[SharpeningUpgrd]:clone()
		ToolSharpening.parent = workspace.player
		ToolSharpening.Positon = Vector3.new(workspace.player.RightHand.Position)
		

	end)

Don’t ever use workspace.player. Use workspace:FindFirstChild(player.Name)

Edited script:

game.Players.PlayerAdded:Connect(function(player)
	repeat wait() until player and player.Character
	wait(5)
	local SharpeningUpgrdScript = require(game.ReplicatedStorage.sharpening.sharpening)	
	local SharpeningUpgrd = player.Tools.SharpeningUpgrd.Value
	local ReplicatedStorage = game:GetService("ReplicatedStorage")
		
	local ToolSharpening = ReplicatedStorage.SharpeningTool[SharpeningUpgrd]:clone()
		ToolSharpening.parent = workspace:FindFirstChild(player.Name)
		ToolSharpening.Positon = Vector3.new(workspace:FindFirstChild(player.Name).RightHand.Position)
	end)
1 Like

Surprisingly, Stone is a part but for some reason it cannot attach to the player

Use Parent with a capital P

This text will be blurred

1 Like

You should be using local Character = Player.Character or Player.CharacterAdded:Wait() to reference a player’s character model not workspace:FindFirstChild(Player.Name).

game.Players.PlayerAdded:Connect(function(player)
	local char = player.Character or player.CharacterAdded:Wait() --Reference player's character with this.
	task.wait(5) --Use 'task.wait' here.
	local SharpeningUpgrdScript = require(game.ReplicatedStorage.sharpening.sharpening)	
	local SharpeningUpgrd = player.Tools.SharpeningUpgrd.Value
	local ReplicatedStorage = game:GetService("ReplicatedStorage")

	local ToolSharpening = ReplicatedStorage.SharpeningTool[SharpeningUpgrd]:Clone() --'clone' should be capitalised.
	ToolSharpening.Parent = char --Use character reference from earlier.
	ToolSharpening.CFrame = char.RightHand.CFrame --This is only going to be valid for 'R15' avatar types.
end)

Better idea! I was worried it would break his script, so I used a little on-the-nose solution