Script doesn't work and it doesn't give any error

Hello! My script doesn’t work and it doesn’t give any error after I trigger the prompt. How can I fix this script?

Here is my script:

local prompt = script.Parent

prompt.Triggered:Connect(function(player)
	game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Wait()

	wait()

	local cape = game:GetService("ServerStorage"):WaitForChild("Cape1.0"):Clone()
	cape:SetPrimaryPartCFrame(player.Character.UpperTorso.CFrame)
	cape.Parent = player.Character
	local Weld = Instance.new("Weld")
	Weld.Parent = player.Character.UpperTorso
	Weld.Part0 = player.Character.UpperTorso
	Weld.Part1 = cape.PrimaryPart
	Weld.C0 = CFrame.new(0,-0.91,0.06)
	Weld.C1 = CFrame.Angles(0, 0, 0)
	end)
end)

Here is a video:
https://i.gyazo.com/8bb55726f7f1fd6be8942d22120e4289.mp4

Try this:

local prompt = script.Parent

prompt.Triggered:Connect(function(player)
player.CharacterAdded:Wait()

wait()

local cape = game:GetService("ServerStorage"):WaitForChild("Cape1.0"):Clone()
cape:SetPrimaryPartCFrame(player.Character.UpperTorso.CFrame)
cape.Parent = player.Character
local Weld = Instance.new("Weld")
Weld.Parent = player.Character.UpperTorso
Weld.Part0 = player.Character.UpperTorso
Weld.Part1 = cape.PrimaryPart
Weld.C0 = CFrame.new(0,-0.91,0.06)
Weld.C1 = CFrame.Angles(0, 0, 0)

end)

1 Like

game.Players.PlayerAdded only runs when a player joins the game so your code will not run until the player has joined the game. But that has already happened, so the code will never actually end up running

1 Like

That didn’t work. I think I already tried that.

You probably don’t want to wait for the player to respawn if they already have a character. It’s also recommended to set parent after setting properties.

local prompt = script.Parent

prompt.Triggered:Connect(function(player)
	local character = player.Character or player.CharacterAdded:Wait()

	local cape = game:GetService("ServerStorage"):WaitForChild("Cape1.0"):Clone()
	cape:SetPrimaryPartCFrame(player.Character.UpperTorso.CFrame)
	
	local Weld = Instance.new("Weld")
	Weld.Part0 = character.UpperTorso
	Weld.Part1 = cape.PrimaryPart
	Weld.C0 = CFrame.new(0,-0.91,0.06)
	Weld.C1 = CFrame.Angles(0, 0, 0)
	Weld.Parent = character.UpperTorso
	
	cape.Parent = player.Character
	end)
end)
1 Like

That works! Thank you so much! :DD