So following my first question, I did some scripting tutorials and leaned a bit of scripting. What I'm trying to achieve here is that when people click the part, they instantly die. I have added the script and click detector inside the part. My code is below.
local part = script.Parent local function kill(otherpart) local partparent = otherpart.parent local humanoid = partparent:FindFirstChild("Humanoid") if humanoid then humanoid.Health = 0 end end part.MouseClick:connect(kill)
Please tell me where I went wrong. Thank you!
Hey the mistake you made was that "otherpart" is not equal to a part of the player but is equal to game.Players[playername] meaning that otherpart.Parent will be equal to game.Players. Try this script i made that should work :)
local part = script.Parent part.ClickDetector.MouseClick:Connect(function(plr) -- An event that activates a function when the part is clicked. local humanoid = plr.Character:FindFirstChild("Humanoid") -- Finds the players humanoid if humanoid then -- Checks if the player has a humanoid. humanoid.Health = 0 -- Kills the player end end)