The goal here is to kill the player once they trigger the proximity prompt, how do I reference the humanoid here?
local player = game.Players.LocalPlayer
local character = player.Character
local humanoid = character.Humanoid
local part = script.Parent
part.ProximityPrompt.Triggered:Connect(function(character)
humanoid.Health = 0
character.Humanoid.Health = 0
end)
EDIT: I made a huge mistake! I told you to put the Local Script in Workspace! This will not work! For now just put it in StarterGui
I assume you are using a “regular” script, in that case: “Regular” scripts cannot access the local player, only Local Scripts can. You have to use a RemoteEvent, fire it in the script when the prompt is triggered, then, on a local script in StarterGui kill the player when the event is fired. In code this would look like this:
The script (The one in the proximity prompt)
local part = script.Parent
part.ProximityPrompt.Triggered:Connect(function(player)
game:GetService("ReplicatedStorage").KillEvent:FireClient(player) --Put a RemoteEvent in Replicated Storage called "KillEvent"
end)
The Local Script (In StarterGui)
local LocalPlayer = game:GetService("Players").LocalPlayer
local Character = LocalPlayer.Character
local Humanoid = Character:WaitForChild("Humanoid")
game:GetService("ReplicatedStorage").KillEvent.OnClientEvent:Connect(function()
Humanoid.Health = 0
end)
You should be setting the humanoid health on the server, not on the client. This can be done by firing an event on the client, receiving it on the server and setting the health to 0 on the server.