Why Does My Script Doesn't Work ?!?! :o

the next scripts after the script he gave me :

local function CreatePrompt(Character)
local torso = Character:WaitForChild(“Torso”)
local hum = Character:WaitForChild(“Humanoid”)
local prox = Instance.new(“ProximityPrompt”, torso)
prox.ActionText = “Womp Womp”
prox.ObjectText = “Womp Womp Him Until He Dies !”

prox.Triggered:Connect(function(t)
	local anim = hum:LoadAnimation(script.Animation)
	anim:Play()
	wait(1)
	t.Character.Humanoid.Health = 0
end)

end

game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
CreatePrompt(Character)
end)
end)
for _, Player in ipairs(game.Players:GetPlayers()) do
local Character = Player.Character or Player.CharacterAdded:Wait()
CreatePrompt(Character)
Player.CharacterAdded:Connect(CreatePrompt)
end

That’s in a server script. Add that code to a server script and you should be good to go.

i did don’t worry the thing that i want to do is disable the feature for the player to kill himself

thats what this code does, inside a local script.

will this work:

if plr.CharacterAdded:Connect(function()
plr.prox.Enabled = false
end)

btw im facing a problem of animation it doesn’t play correctly and doesn’t play fully

No it wont, here’s how you can fix it

  1. Create a new LocalScript inside StarterCharacterScripts
  2. Paste this code:
local Character = script.Parent
Character.DescendantAdded:Connect(function(Desc)
	if Desc:IsA("ProximityPrompt") then
		Desc.Enabled = false
	end
end)
for _, Desc in ipairs(Character:GetDescendants()) do
	if Desc:IsA("ProximityPrompt") then
		Desc.Enabled = false
	end
end

Let me know if it works

1 Like

it works !! but is there a way to fix animation?

I made a small error in my previous script, here is the updated one:
Now the animation should be loaded as soon as the character is created, and then played when the prompt is triggered.

local function CreatePrompt(Character)
	local torso =  Character:WaitForChild("Torso")
	local hum = Character:WaitForChild("Humanoid")
	local prox = Instance.new("ProximityPrompt", torso)
	prox.ActionText = "Womp Womp"
	prox.ObjectText = "Womp Womp Him Until He Dies !"
	local anim = hum:LoadAnimation(script.Animation)
	
	prox.Triggered:Connect(function(t)
		anim:Play()
		wait(1)
		t.Character.Humanoid.Health = 0
	end)
end

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		CreatePrompt(Character)
	end)
end)
for _, Player in ipairs(game.Players:GetPlayers()) do
	local Character = Player.Character or Player.CharacterAdded:Wait()
	CreatePrompt(Character)
	Player.CharacterAdded:Connect(CreatePrompt)
end

it needs to be the opposite the triggerer is the one who plays animation but the script does the complete opposite @sickbadassdragon

When a prompt is triggered, it returns the player who triggered it aswell.

here, t means the player who triggered the prompt.
Using this, find the triggered player’s humanoid/animator, load the animation and play it.

@GalladeR475 explained it before me

Here is the updated code:

local LoadedAnimations = {}
local function CreatePrompt(Character)
	local torso =  Character:WaitForChild("Torso")
	local hum = Character:WaitForChild("Humanoid")
	local prox = Instance.new("ProximityPrompt", torso)
	prox.ActionText = "Womp Womp"
	prox.ObjectText = "Womp Womp Him Until He Dies !"
	LoadedAnimations[Character] = hum:LoadAnimation(script.Animation)

	prox.Triggered:Connect(function(PlayerWhoTriggered)
		if LoadedAnimations[PlayerWhoTriggered.Character] then
			LoadedAnimations[PlayerWhoTriggered.Character]:Play()
		end
		wait(1)
		PlayerWhoTriggered.Character.Humanoid.Health = 0
	end)
end

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		CreatePrompt(Character)
	end)
end)
for _, Player in ipairs(game.Players:GetPlayers()) do
	local Character = Player.Character or Player.CharacterAdded:Wait()
	CreatePrompt(Character)
	Player.CharacterAdded:Connect(CreatePrompt)
end

Let me know if it works.

You need to kill the player, not the player who triggered (I think thats what OP wants)

Load the animation in the humanoid of the player who triggered, not the player itself.

I’m not exactly sure what they want to be honest, in the original code that’s how it was.

Well, OP wants to so that the player who triggered plays an animation when they interact with the prompt, and the player dies.

exactly what i want

1111111111111111111

In that case you can simply replace PlayerWhoTriggered.Character.Humanoid.Health = 0 with hum.Humanoid.Health = 0

Updated

local LoadedAnimations = {}
local function CreatePrompt(Character)
	local torso =  Character:WaitForChild("Torso")
	local hum = Character:WaitForChild("Humanoid")
	local prox = Instance.new("ProximityPrompt", torso)
	prox.ActionText = "Womp Womp"
	prox.ObjectText = "Womp Womp Him Until He Dies !"

	prox.Triggered:Connect(function(PlayerWhoTriggered)

		local Animation = LoadedAnimations[PlayerWhoTriggered]; 
		if (not Animation) then
			LoadedAnimations[PlayerWhoTriggered] = PlayerWhoTriggered.Character.Humanoid:LoadAnimation(script.Animation) --// bad practice, avoid at all costs
			Animation = LoadedAnimations[PlayerWhoTriggered]; 
		end
		Animation:Play();
		task.wait(1)
		hum.Health = 0
	end)
end

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		CreatePrompt(Character)
	end)
end)
for _, Player in ipairs(game.Players:GetPlayers()) do
	local Character = Player.Character or Player.CharacterAdded:Wait()
	CreatePrompt(Character)
	Player.CharacterAdded:Connect(CreatePrompt)
end

hey btw a question does the animation not work fully in studio and works fully in the game?