#this is not working for no reason

112 messages · Page 1 of 1 (latest)

upper condor
#

do that but in the local script

edgy berry
#
script.Parent.Touched:Connect(function(otherPart)
    local character = otherPart.Parent
    local humanoid: Humanoid = character:FindFirstChildOfClass("Humanoid")
    
    if humanoid and humanoid.Health > 0 then
        humanoid.Health = 0
    end
end)
#

parent a script to your part and paste this code

spring idol
#

At least explain the code so he can understand properly how it works.

edgy berry
#

real

spring idol
#

I'll help you understand this in a bit

edgy berry
#

Alr

#

It also didn't work

edgy berry
#

Bet

#

I just wanna be programmer

edgy berry
#

Because this kill brick will

#

Doxx the player

#

Permamently ban the player

#

Deletes everything in the workspace

#

oh wait it worked

edgy berry
#

but i didnt under anything of this code

#

Understand?

#
script.Parent.Touched:Connect(function(otherPart)
    local character = otherPart.Parent
    local humanoid: Humanoid = character:FindFirstChildOfClass("Humanoid")
    
    if humanoid and humanoid.Health > 0 then
        humanoid.Health = 0
    end
end)
#

yeah

#

Touched = when player touch the part duh

#

ik

#

wait

#

Local character finds the character

#

Who touched the part

#

Uwu

#

And then it will select humanoid

#

Set health to 0

#

Done simple

#

what is the diffrence between findfirstchild and findfirstchildofclass

peak creek
edgy berry
#

and ofclass?

peak creek
#

findfirstchildofclass finds the class of an instance

#

for example findfirstchildofclass("Humanoid")

#

or BasePart

#

or MeshPart

edgy berry
#

alr thanks

#

The difference between FindFirstChild and FindFirstChildOfClass in Roblox Lua is in what they search for and how specific their search criteria are.

peak creek
#

theres alot of classes coolguy

edgy berry
#

OH CMON IT TOOKED ME 5 MINUTES CORRECTING MA GRAMMAR

#

But yeah you get the point

edgy berry
#

...

#

alr bye

#

wait

#

what is diffrence between local function and function

unreal cedarBOT
#

studio** You are now Level 2! **studio

edgy berry
#

Your roles said I can ask you for coring thingy

#

Coding*

edgy berry
#

:p

#

dude..

peak creek
#

ok that was mean mb

#

uuuhhh

edgy berry
#

um guys just help me im new

peak creek
#

im assuming because of that you do not know nothing

#

so uuuhhh

edgy berry
#

In Lua, including Roblox Lua scripting, the difference between local function and function pertains to the scope and visibility of the function.

peak creek
#

it will teach you lots of useful stuff

edgy berry
#

He aint reading allat

#

Local function is find player and execute it to only them

#

Function = everyone else

peak creek
#

what youtube tutorials? that would work

edgy berry
#

my problem is when i search for tutorial in utube its old and their codes doesnt work

peak creek
#

👍

#

its by roblox themselves

#

and updated

peak creek
#

"Youchube" ☕

spring idol
#
local Part : BasePart = script.Parent
--[[
-- The part that's outside the script.
-- the ": BasePart" is a method for letting the code know to what class to expect to.
-- It let's the script know that we are dealing with a humanoid type when we addressed the local.
-- This allows to the code error properly, and you to autocomplete it's functions and signals.
-- The same is done with the humanoid.
-- ]]

function onTouch(BasePart)
  -- The function onTouch (look at the last line to understand the setup)
  -- This function comes with the argument "BasePart" from the ".Touched" signal which is the BasePart that touched our Part.

  local Character = BasePart.Parent
  local Humanoid : Humanoid = Character:FindFirstChildOfClass("Humanoid")
  --[[
  -- Since we want to detect if a player is touching the part,
  -- we are trying to figure out if we the touching BasePart is actually one of them.
  -- If a leg for example is that touching BasePart we assume we can go to it's parent, the character,
  -- and find the humanoid inside it to kill the player.
  -- As for the :FindFirstChildOfClass() it's a function to find the instance with the class name we insert, in our case it's the humanoid.
  --]]
  
  if Humanoid and Humanoid.Health > 0 then
    Humanoid.Health = 0
  end
  --[[
  -- Here we are checking if we have a humanoid (and) a living humanoid.
  -- We do this check so we can verify that the character was actually a character
  -- and the same for the humanoid.
  -- If both conditions are met, we set the health to 0 so the player will die.
  -- ]]

end -- The end of the function.


Part.Touched:connect(onTouch)
--[[
-- Here we set a connection to the function "onTouch"
-- This function executes once the signal ".Touched"
-- has been activated, which is whenever a BasePart type
-- is touching the BasePart we are connecting it to.
-- ]]
#

This is for you too @edgy berry

edgy berry
#

alr thank you

#

@spring idol

spring idol
#

Yes?

edgy berry
#

may i ask u a quetion

spring idol
#

Shoot it

edgy berry
#

local humanoid : humanoid what does it do

#

like

#

what does it mean

#

like just type local humanoid equal

loud berry
#

bro

#

you just forgot the cap

#

you wrote humanoid instead of Humanoid

spring idol
#

It let's the script know that we are dealing with a humanoid type when we addressed the local.
This allows to the code error properly, and you to autocomplete it's functions and signals.

spring idol
#

If you meant me

loud berry
#

like i mean here

edgy berry
#

alr ty

loud berry
#

its just this cap

#

and ik it because it happened to me too

spring idol
#

So yeah beware that Lua like most programming languages are case sensitive to anything.

spring idol
#

@edgy berry if you need me I'm here

edgy berry
#

how do i add sound when a player touches this part

spring idol
#

Make the question more specific, do you want the sound to play for the one who dies alone?

edgy berry
#

yeah

spring idol
#

You might be aware that the humanoid already plays a death sound, it can just be overwritten.
You can see how to do that with a quick online search.
https://devforum.roblox.com/t/how-do-you-change-the-death-sound/2778411/20

edgy berry
#

nvm

#

i mean the sound that i choose

spring idol
#

Yes, that's exactly what I explained.

edgy berry
#

Yes

#

Now time to sue

spring idol
#

sue?