Hello i have made a script which puts an proximity prompt inside the players HumanoidRootPart however when the player dies the prompt isnt cloned back in the players HumanoidRootPart
local Players = game:GetService("Players")
local RS = game:GetService("ReplicatedStorage")
local RemoteEvent = RS:WaitForChild("HostageEvent")
local players = game:GetService("Players")
players.PlayerAdded:Connect(function(player) -- connects to a function when a player joins, with a player variable
local prompt = RS:WaitForChild("HostagePrompt"):Clone()
player.CharacterAdded:wait() -- waits for character to prevent "attempt to index nil with character" error
prompt.Parent = player.Character:WaitForChild("HumanoidRootPart") -- parents the proxprompt instance to humanoidrootpart
end)
You wanna listen for when the character is added and not the player. PlayerAdded only runs once and therefore the prompt is cloned only one
New script:
local Players = game:GetService("Players")
local RS = game:GetService("ReplicatedStorage")
local RemoteEvent = RS:WaitForChild("HostageEvent")
local players = game:GetService("Players")
players.PlayerAdded:Connect(function(player) -- connects to a function when a player joins, with a player variable
player.CharacterAdded:Connect(function()
local prompt = RS:WaitForChild("HostagePrompt"):Clone()
prompt.Parent = player.Character:WaitForChild("HumanoidRootPart") -- parents the proxprompt instance to humanoidrootpart
end)
end)