Simple script not working

local tool = script.Parent
local rep = game:GetService("ReplicatedStorage")
local part = rep:WaitForChild("Part")
game.Players.PlayerAdded:Connect(function(plr)
	local char = plr.Character or plr.CharacterAdded:Wait()
	local head = char:WaitForChild("Head")
	local function a()
	local CLONE = part:Clone()
    CLONE.Parent = workspace
		CLONE.CFrame =  head.CFrame * CFrame.new(0,0,-10)
		
	
	end

		tool.Activated:Connect(a)
		
	end)

What do you want to achieve and whats wrong?

1 Like

when u click the tool while it is equipped a part from replicated storage will be cloned and be infront of your head

are there any errors? What is not working?

1 Like

Nope,No errors in output i think its the function thats not working
Btw the script is a normal script

I feel like the problem is with the function end line, where its indented when its not supposed to be, then again I’m not exactly sure. Your code is a bit difficult to read, no offense. Maybe another reason why, is because it looks like your calling the function when its sandwiched in between the end lines making the function not activate.

1 Like

The player added function is causing the issue. Remove that. And inside the function, redefine character as tool.Parent
and head as character:FindFirstChild(“head”)
Edited script:

local tool = script.Parent
local rep = game:GetService("ReplicatedStorage")
local part = rep:WaitForChild("Part")
local function a()
	local Char = tool.Parent
	local Head = Char:FindFirstChild("Head")
	local CLONE = part:Clone()
	CLONE.Parent = workspace
	CLONE.CFrame =  Head.CFrame * CFrame.new(0,0,-10)


end

tool.Activated:Connect(a)

1 Like

Any ideas on how the plr added is causing the issue?

You don’t want to listen for every player joining the game as it is useless for what you want. Instead you only need to listen for tool activation. When the tool is activated, find the character holding it, and put a part

1 Like