#i have a quick question

1 messages · Page 1 of 1 (latest)

lavish lake
#

(click to read more) How do i make an if character touched the part then it'll do something because i have no idea

fast mesa
#

Just do in the part

#

Put a script in the part

#

The script

lavish lake
#

no, this is a module script which is used by event manager

smoky lake
#

use the touched event

#

on a part

fast mesa
#

Yeah I was typing that

stable hare
#

use the touched event

lone venture
#

One message removed from a suspended account.

fast mesa
#

Script.parent.touched:connect(function(hit)
if not hit.parent:Findfirstchild() then;end;

lone venture
#

One message removed from a suspended account.

stable hare
#

Script.parent.touched:connect(function(hit)
if not hit.parent:Findfirstchild() then;end;

drowsy rivet
#

doesnt even work lol

lavish lake
#

bro i didnt except 5 person to answer my question at same time

fast mesa
#

Rough script

#

Not exactly

lavish lake
#

btw heres code with Mimical's suggestion:

local HEsHEre = {}

local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local entity = ServerStorage.Entities.HEsHEre
function HEsHEre.Trigger(player)
    print("HE IS HERE")
    local clonedEntity = entity:Clone()
    clonedEntity.Parent = workspace
    clonedEntity.Position = Vector3.new(
        math.random(0, 100),
        math.random(0, 100),
        math.random(0, 100)
    )
    local character = player.Character or player.CharacterAdded:Wait()
    local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
    local humanoid = character:FindFirstChild("Humanoid")
    local function onTouched(clonedEntitiy)
        
    end
    wait(40)
    clonedEntity:Destroy()
end
return HEsHEre
drowsy rivet
#

U forgot to add ) after end

lavish lake
#

will it work?

drowsy rivet
#

that just wont do anything ngl

#

I dont see you connecting the .touched event to anything

lavish lake
#

lemme add print into onTouched

drowsy rivet
#

iin the doc

lavish lake
#

ok

drowsy rivet
#

the functions are there for what to do on touch, but they are still just functions on their own

#

U need to connect the touched event to the function

lavish lake
#
local HEsHEre = {}

local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local entity = ServerStorage.Entities.HEsHEre
function HEsHEre.Trigger(player)
    print("HE IS HERE")
    local clonedEntity = entity:Clone()
    clonedEntity.Parent = workspace
    clonedEntity.Position = Vector3.new(
        math.random(0, 100),
        math.random(0, 100),
        math.random(0, 100)
    )
    local character = player.Character or player.CharacterAdded:Wait()
    local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
    local humanoid = character:FindFirstChild("Humanoid")
    local function onTouched(clonedEntitiy)
        print("player touched the entity")
    end
    clonedEntity.Touched:Connect(onTouched)
    wait(40)
    clonedEntity:Destroy()
end
return HEsHEre
hasty kilnBOT
#

studio** You are now Level 8! **studio

lavish lake
#

ill do like, test

#

first im gonna touch the entity's hitbox then see if it printed

#

bruh

  16:29:19.248  Workspace.Events.1_HEsHEre:15: attempt to index nil with 'Character'  -  Server - 1_HEsHEre:15
  16:29:19.248  Stack Begin  -  Studio
  16:29:19.248  Script 'Workspace.Events.1_HEsHEre', Line 15 - function Trigger  -  Studio - 1_HEsHEre:15
  16:29:19.248  Script 'ServerScriptService.EventTEST', Line 26 - function activateRandomEvent  -  Studio - EventTEST:26
  16:29:19.248  Script 'ServerScriptService.EventTEST', Line 42  -  Studio - EventTEST:42
  16:29:19.248  Stack End  -  Studio```
drowsy rivet
#

Btw heres what .touched does:
When you connect .touched to a base part, it'll activate on anything that touches that basepart.
So if you connect .touched to a random part, itll activate if any other part touches it, or player or anything (as long as it has cantouch on).
The parameter inside the touched function is the part that hit the basepart with the connected function. So if the player torso hit the basepart, itll be the playertorso.

lavish lake
#

then ill use different variable

drowsy rivet
#

If u want to check whether the part that touched the basepart is the player, you would do check the if hit.Parent has a humanoid. If it does, it means the player touched the basepart, if it doesnt, then it means another part touched the basepart

#

I would recommend adding some prints to the parameter for touched cause itll help you understand it much better (cause you can see what the hit part is)

lavish lake
drowsy rivet
#

yea

lavish lake
#

why unknown global

drowsy rivet
#

its supposed to match the parameter u give in the function

#

most people put "hit" as the param

#

u have clonedEntitiy or sum

lavish lake
#

ye

#

i have cloned entitiy

drowsy rivet
#

yea no not what im talking about

lavish lake
#

TYPO

drowsy rivet
#

doesnt matter lol

lavish lake
#

i accidently put i

drowsy rivet
#

shouldnt match the part u connected it to

#

will cause confusion

lavish lake
#

ok lemme test

drowsy rivet
#

u know how functions work right

#

local function test(hit)
print(hit)
end
test("hello")
#

stuff like that

#

parameters are inside the brackets

drowsy rivet
#

waiting

lavish lake
#

is it like this?

drowsy rivet
#

no

#

the variable u put inside the onTouched brackets is a new one

lavish lake
#

but for some reason theres Touched existed

drowsy rivet
#

Its not supposed to match anything old

lavish lake
#

idk lemme test it and see if anythings happen

drowsy rivet
#
local function onTouched(hit)
print(hit)
end

clonedEntity.Touched:Connect(onTouched)
fast mesa
#

Why do you have an if statement for touched

drowsy rivet
#

making duplicate variable names can cause confusion for you and the script

lavish lake
#

lemme make a duplicated variable different

#

name*

drowsy rivet
#

and then test

#

then u can see what the touched event prints

#

from there u can more easily decide how to proceed

lavish lake
#

changed it

drowsy rivet
#

bro just removed capitalization

#

for your own sake id recommend naming it something different, cause it can cause you confusion in the future

lavish lake
#

no, ill notice it

drowsy rivet
#

just call it hit

#

cause it doesnt guarantee that that value is a cloned entity

fast mesa
lavish lake
#

ok

drowsy rivet
#

and inside the function just print(hit) and press play

#

so u can see what it prints

lavish lake
drowsy rivet
#

yea

fast mesa
#

Minimal does
If part.touched == true then
Even work?

drowsy rivet
#

Do parts have a .touched boolean property?

#

You can answer your question with that

lavish lake
#

same error

  16:42:00.785  Workspace.Events.1_HEsHEre:15: attempt to index nil with 'Character'  -  Server - 1_HEsHEre:15
  16:42:00.785  Stack Begin  -  Studio
  16:42:00.785  Script 'Workspace.Events.1_HEsHEre', Line 15 - function Trigger  -  Studio - 1_HEsHEre:15
  16:42:00.786  Script 'ServerScriptService.EventTEST', Line 26 - function activateRandomEvent  -  Studio - EventTEST:26
  16:42:00.786  Script 'ServerScriptService.EventTEST', Line 42  -  Studio - EventTEST:42
  16:42:00.786  Stack End  -  Studio```
drowsy rivet
#

can u send ss of the output so we can have colors

lavish lake
drowsy rivet
#

local character = player.Character or player.CharacterAdded:Wait()
this part is causing the issue.

#

What is player?

lavish lake
drowsy rivet
#

nope

#

thats "Players"

#

not "player"

#

player is passed as a parameter in the function

lavish lake
drowsy rivet
#

Yea whats player

#

What is the value when the function is ran

lavish lake
#

oh wait i think its the problem at line function HEsHEre.Trigger(player)

drowsy rivet
#

its the problem at line 15

#

due to player being nil likely

#

do u pass a player

#

when u run the function

fast mesa
#

Show mimical the line where u call that function

lavish lake
#

but how am i gonna get the humanoid of the character because the character model is old roblox noob player

drowsy rivet
#

We're going step by step rn

#

How are you triggering the .Trigger function

#

where

#

show

lavish lake
#
print("EventManager script started.")
local EventsFolder = workspace:FindFirstChild("Events")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local eventsFolder = workspace.Events
local TestModule = require(eventsFolder:FindFirstChild("1_HEsHEre"))

if EventsFolder then
    print("Events folder found.")
    local events = {}

    for _, eventModule in EventsFolder:GetChildren() do
        if eventModule:IsA("ModuleScript") and string.match(eventModule.Name, "^%d+_") then
            table.insert(events, require(eventModule))
        end
        print("Collected all of events")
    end

    local function activateRandomEvent()
        print("Started activateRandomEvent")
        if #events > 0 then
            local randomIndex = math.random(1, #events)
            local randomEvent = events[randomIndex]
            print("Stored the event function")

            if randomEvent == TestModule then
                TestModule.Trigger() -- here
            else
                randomEvent() 
                print("Called other events")
            end
        else
            warn("No valid events found in Events folder.")
        end
        print("Function random event is working")
    end


    while true do
        print("Starting main loop iteration.")
        task.wait(10)
        task.wait(math.random(10, 15))
        activateRandomEvent()
    end
else
    warn("Events folder not found in Workspace.")
end
drowsy rivet
#

Yea u dont pass any variable

#

in .Trigger

#

so thats why its nil

#

and why its breaking

lavish lake
#

i dont think you noticed the TestModule variable present

#

local TestModule = require(eventsFolder:FindFirstChild("1_HEsHEre"))

drowsy rivet
#

all i need to see is this

#

u dont pass an argument

#

while there is a parameter in the function inside the module

fast mesa
#

Mich you need to put the player in the brackets

lavish lake
#

bro, it worked before

drowsy rivet
#

Print player inside the function

#

see what it says

lavish lake
#

when i tested without the player checking if it touched part

#

the entity cloned then put in workspace then teleported

drowsy rivet
lavish lake
drowsy rivet
#

trigger

lavish lake
#

in module script (where HEsHEre event is present) or event manager script?

drowsy rivet
#

module

lavish lake
#

this is what happened

drowsy rivet
#

Just print it without any string or anything

#

print(player)

lavish lake
#

ok

drowsy rivet
#

its not gonna be a perm print, so its fine to not have a clear print

lavish lake
#

it printed "nil"

drowsy rivet
#

exactly

#

so you need to pass the player when u activate the function

lavish lake
#

but how am i gonna get the humanoid of the player?

drowsy rivet
#

What?

#

We are talking about passing the player when we trigger the function

#

we arent talking about getting the humanoid

lavish lake
drowsy rivet
#

is event manager local or server

drowsy rivet
lavish lake
#

server

drowsy rivet
#

okay

#

Wait so what are you even doing with the player then?

lavish lake
#

the entity appear for everyone and when someone touches it, it'll trigger jumpscare screen in everyone's screen

drowsy rivet
#

Okay

#

can u resend trigger function script

#

dont wanna scroll each time

lavish lake
#

ok

#
local HEsHEre = {}

local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local entity = ServerStorage.Entities.HEsHEre
function HEsHEre.Trigger()
    print("HE IS HERE")
    local clonedEntity = entity:Clone()
    clonedEntity.Parent = workspace
    clonedEntity.Position = Vector3.new(
        math.random(0, 100),
        math.random(0, 100),
        math.random(0, 100)
    )
    local character = player.Character or player.CharacterAdded:Wait()
    local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
    local humanoid = character:FindFirstChild("Humanoid")
    local function onTouched(hit)
        if clonedEntity.Touched == true then
            print(hit)
        end
    end
    clonedEntity.Touched:Connect(onTouched)
    wait(40)
    clonedEntity:Destroy()
end
return HEsHEre
drowsy rivet
#

okay cool u removed the parameter

#

yea so currently u dont need anything related to the humanoid

#

u connect a touched event to the part thats spawned

#

with that u want to check whether the player touched the part

#

ill tell u how to do that in a sec

#

but first

#

remove this

lavish lake
#

um after i removed these lines, this happened

#

wait

drowsy rivet
#

yea idk what u just did

#

but its supposed to be :Connect(onTouched)

lavish lake
#

lemme switch that to clonedEntity

drowsy rivet
#

no

#

no

#

u need to put the function name in the brackets

#

so :Connect(onTouched)

lavish lake
#

okay it fixed

drowsy rivet
#

cool

lavish lake
#

okay whats next step

drowsy rivet
#

now next step is to remove the if statement inside onTouched, cause the function only triggers when u touch the part so its irrelevant

#

After that i want you to add the following in the function:

print(hit)
print(hit.Parent)
#

and press play to see what it prints out

#

Im doing this so you can visualize better what exactly the hit variable is

lavish lake
#

ok

#

bruh he spawned in the sky, lemme disable a teleport code temporarily

drowsy rivet
#

U can move it if u go server side

lavish lake
#

i disabled by doing this

drowsy rivet
#

Just make sure its base position is reachable

lavish lake
#

um what, it didnt print anything when i touched its hitbox

drowsy rivet
#

whjere did u check

#

thge output

lavish lake
drowsy rivet
#

u dont need that if statement i said btw

lavish lake
drowsy rivet
#

since the function only triggers if the part is touched

lavish lake
#

(ignore that other infinite yeild warn)

drowsy rivet
#

Can u send video

lavish lake
#

ok lemme send video since i have nitro (lasts for 1 hour right now)

#

ok uploading

#

i need to eat so be right back and you can anylaze the video

drowsy rivet
#

What are the entities properties

#

Specifically canTouch

lavish lake
#

canTouch is enabled

drowsy rivet
#

okay

lavish lake
drowsy rivet
#

Btw quick tip: use debrisservice for this

#

Secondly can you change the onTouched function to this please?

local function onTouched(hit)
  print(hit)
  print(hit.Parent)
end
#

without the if statement

lavish lake
#

ok im back

lavish lake
drowsy rivet
#

Alright cool

#

So now that you have those prints, what do you see?

lavish lake
drowsy rivet
#

Im talking specifically the prints

lavish lake
#

and when i stop walking, the spam print stops

drowsy rivet
#

What are they printing

lavish lake
# lavish lake alr it worked when i touched the entity's hitbox

they print these

  17:19:45.370  michaelamgad  -  Server - 1_HEsHEre:17
  17:19:45.482  Right Arm  -  Server - 1_HEsHEre:16
  17:19:45.486  michaelamgad  -  Server - 1_HEsHEre:17
  17:19:45.488  Torso  -  Server - 1_HEsHEre:16
  17:19:45.492  michaelamgad  -  Server - 1_HEsHEre:17
  17:19:45.495  head  -  Server - 1_HEsHEre:16
  17:19:45.500  michaelamgad  -  Server - 1_HEsHEre:17
  17:19:45.502  Right Leg  -  Server - 1_HEsHEre:16
  17:19:45.506  michaelamgad  -  Server - 1_HEsHEre:17
  17:19:45.507  Left Arm  -  Server - 1_HEsHEre:16
  17:19:45.511  michaelamgad  -  Server - 1_HEsHEre:17
  17:19:47.449  Right Leg  -  Server - 1_HEsHEre:16
  17:19:47.453  michaelamgad  -  Server - 1_HEsHEre:17```
drowsy rivet
#

Yea i am aware

#

but what exactly are they

#

Like what is "Left Leg"

#

like that

#

try to find it in the explorer

lavish lake
#

its in old roblox noob character model

drowsy rivet
#

michaelamgad what about this

lavish lake
#

its my roblox username

#

or player name

drowsy rivet
#

Yep

#

where is it

#

in explorer

lavish lake
#

what the mainSCRIPT does is that it places everything below into its position where 2007 roblox engine works except for unused content

#

as you can see in the video, when i press start. everything gets replaced with old 2007 roblox engine

drowsy rivet
#

Where is michaelamgad located

#

after pressing play

lavish lake
#

including the erik.cassel model

lavish lake
drowsy rivet
#

Yea

lavish lake
#

after pressing play, the model named "michaelamgad" appeared

drowsy rivet
#

So based on that knowledge, how can you get the humanoid?

lavish lake
#

in michaelamgad.humanoid

drowsy rivet
#

Yea

#

Btw rq whats your goal again inside the .Touched function?

#

What are you trying to do?

lavish lake
#

well i want the jumpscare screen to appear which is this for 1 second then disappears and the entity itself disappears

drowsy rivet
#

Okay so with the .Touched event you have achieved the ability to run code when the entity is touched

lavish lake
#

ye

#

ima code that to happen rn

drowsy rivet
#

What you would want to do now, is check whether the part that touched the entity is the character (u can do this by checking for humanoid). After that you run the jumpscare on the character

lavish lake
#

um it already activates when the player touches the entity's hitbox

#

without adding the check

drowsy rivet
#

Yea but it currently would also activate if another random part happened to touch the entity

#

So you just need to add a check to make sure it was the character that touched the entity

lavish lake
#

ok

lavish lake
hasty kilnBOT
#

studio** You are now Level 9! **studio

drowsy rivet
#

yes that checks it correctly

lavish lake
#

ok

#

ima also add smth else

drowsy rivet
#

Btw as you mightve seen in the prints, whenever the player hits the entity, it sent multiple prints for different limbs

#

This will make it so the .touchedevent can trigger multiple times

#

To combat this i would recommend either adding a debounce or disconnecting the function once the character hit it

lavish lake
#

bro, the gui wont appear on my screen

drowsy rivet
#

Yea u are grabbing the gui from startergui

#

that doesnt do anything

lavish lake
#

wait

#

lemme switch to PlayerGui

drowsy rivet
#

when u press play the startergui gets replicated into the player inside the playersfolder

#

player.PlayerGui

lavish lake
#

here are the results of this HEsHEre event (uploading the video)

drowsy rivet
#

So it works now?

lavish lake
#

bro the entity's hitbox is 50 studs large

drowsy rivet
#

u can change that

lavish lake
#

its not supposed to trigger if the player touched its old hitbox which is 4 studs big

#

i mean

#

the HEsHEre part is 50 studs large

drowsy rivet
#

u can make an invisible hitbox for the actual hit and the entity itself can be bigger (with canTouch off)

lavish lake
#

oh wait i think 50 studs big is not big enough

#

lemme make it 75 studs big

#

and done

#

ok i think the event itself is done. Thank you for helping me @drowsy rivet

drowsy rivet
#

Cool nws

lavish lake
#

after the entity teleported to random position, i ran to it then touched it then the jumpscare worked