How would I reference a character?

When someone spawns, I put a scipt so a folder is put in the character but I want to reference that folder in a separate event. But I can’t figure out how.

Here is the script for the Folder:

script.Parent.Touched:Connect(function(hit)

    local Player = hit.Parent

    local Folder = Instance.new("Folder",Player)

end)
1 Like

Try looking for hit:FindFirstAncestorOfClass("Model"). If it exists, there are two scenarios:

  1. The model isn’t a character, you can check Players:GetPlayerFromCharacter() to see if it returns a player or not.
  2. The model is a character, the opposite return of the first scenario.

The third scenario is no model, probably hit a part directly parented to workspace or something else that doesn’t have a model in its tree.

1 Like

Btw, your player variable is a character model
you need to use game.Players:GetPlayerFromCharacter(hit.Parent) if you want the actual player object

But I cannot mention hit in another script.

Is there a reason why you want to pass the reference to another script?

If that’s the case, you should use a BindableEvent and using Event event when the object was fired using Fire() including the reference. The other script would be listening to the event. Connect a function to BindableEvent.Event.

However, I would advise using a one single script for all, as it is more convenient and easier to manage.

I want to clone Instances that you can summon by clicking while holding a tool in the folder (that is in the character) and then later remove them from another tool

Just looking at this, couldn’t you just put a script inside StarterCharacterScripts to create a Folder for the Character that way instead, then detect the Part’s detection?

local DB = false
local PartToTouch = workspace.Part

local Folder = Instance.new("Folder")
Folder.Parent = script.Parent

PartToTouch.Touched:Connect(function(Hit)
    local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
    if Player and not DB then
        DB = true
        --Do your event firing here
        wait(5)
        DB = false
    end
end)

Then fire the event you want to send throughout the place? Either Server or Local

1 Like

Oh, I had it backwards! Looks like you want to do something like a clone something from somewhere and parent it to the folder. I don’t have enough information to cover the entire issue, can you forward and elaborate the details? I need a clear idea what you’re trying to achieve.

1 Like

No need! But thank you for trying to help I appreciate it alot :slight_smile:

Just curiosity but what is DB?

Basically a Debouce, which pretty much prevents the event from firing multiple times

Say I have this in a infinite loop

local DB = false

while true do
    if DB == false then
        print("Yes")
        DB = true
        wait(5)
        DB = false
    end
    wait()
end

The loop is frequently checking every time if the DB is equal to false, and if it is then we can set it as true! But the next time the loop runs through, it’ll pass the conditional check as the DB is still set to true for 5 seconds

1 Like

Ohhhh ok so it prevents spam! Thank you

1 Like

Pretty much

Just think of it as Firerate for a Automatic Gun LOL

If there was no Firerate cooldown then uhh

Gun go bzrrtrtttttt

Ok thank you :rofl: I understand what debounces are now, this is actually very helpfull

1 Like