Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I setup and finish Function Command?

Asked by 6 years ago

Ok so, im trying to make a script to where if a player touched a part, their limbs would be engulfed in flames. Currently this is my script:

game.Workspace.bodycolor.Head.Touched:Connect(function()
function

end)

The problem is I dont know how to setup the function command. Im doing the fire thing separately because im a beginner and dont know much. Im guessing the command would be:

function.game.workspace.bodycolor.head.effect = fire (or whatever its called) also bodycolor is the name of the test humanoid I am using.

Can anyone please help me?

2 answers

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

Hello it's me. c:

Now with introductions out of the way lol, let's get into this.

This answer's to be used as a reference

For what you're trying to accomplish, you require to use the Touched event of an object (or part), which listens for when another object touches it, and returns said part that touches. Here's an example of that;

Part.Touched:Connect(function(PartThatTouched) -- The `PartThatTouched` is, well, the part that touched the part. lol
    print('I was stepped on by ' .. PartThatTouched.Name .. '! Ack!') -- This should print as a result. XP
end)

Poor Mr Part. :c Oh well. lol Now comes the fun part. >:)

With the Touched event, since it returns the object, we can check whether or not the object belongs to a player via the GetPlayerFromCharacter method. :o What it does's it retrieves the player if it was a player that was touching it, if not it'll return nil. We can use this to aid us in our conquest! :D Just be aware, we can't just check if the object's apart of the player's character's just simply by giving the method the object itself, we need to check it's parent, since it's inside the player's character.

Part.Touched:Connect(function(PartThatTouched)
    local ThePlayerThatTouched = Players:GetPlayerFromCharacter(PartThatTouched.Parent)
    if ThePlayerThatTouched then
        print(ThePlayerThatTouched.Name .. ' stepped on me! >:(')
    end
end)

And, if you checked the output, it should print X stepped on me! >:(

Now, I think we're all done here...

HANG ON!

Oh no, not this again. :c

You forgot something!

What's it?

You didn't explain how to give the player fire!

Oh yeah... lol

Now, since we're now able to tell whether or not touched the object was a player, we can simply loop through the player's character and apply fire to him.

for i, v in pairs(Player.Character:GetChildren()) do -- Loops through the player's character; the `GetChildren` method returns a with what was within the player's character, and the for loop loops through said table.
    if v:IsA('BasePart') then -- Checks if `v` (the current item in the last at that iteration) was an object. If so...
        print('I\'m a part! :D') -- This should print into the output.
    end
end

Ok, now we should be done.

NO U

Dangit. >.<

You forgot to apply the fire!

Right, right.

Now, all we need to do's apply the fire. We can accomplish this by using the Instance.new function, where it'll create a new object. (I don't recommend using it's second parameter though, as it's been deprecated.)

local Fire = Instance.new('Fire')
Fire.Parent = Object -- Just me, or is it getting a *little* hot in here?

Now we should all be done. Are we?

Yay!

Ok. :p

Stuff touched on, but never really explained

  1. Touched - Fires when an object touches another, and returns the part that touched.

  2. GetPlayerFromCharacter - Checks to see if what was given was a player's character; if so, it'll return the player, and if not it'll return nil.

  3. For Loops - For the loop used in this answer, click here. To quote, the dev hub, "The for loop is a way of running a command or set of commands a set number of times."

  4. GetChildren - Returns a table with the children that were within the parent.

  5. IsA - Returns whether an object was a specific class, such as if it was a Part or Fire.

  6. Instance.new - Best I could find. XP What it does's it creates a new object, to put very simply.

If you have anymore questions, please let me know. ;)

0
Second answer after a month! Highfive! ...No? Aw. :c TheeDeathCaster 2368 — 6y
Ad
Log in to vote
0
Answered by
Vain_p 78
6 years ago
Edited 6 years ago

You're question makes no sense:/ If your trying to see if the brick touched the player then do

script.Parent.Touched:Connect(function(part)-- Put this in the brick that you want the touch event to active
    local Parent = part.Parent
    if game.Players:GetPlayerFromCharacter(Parent) then
        Instance.New("Fire").Parent = Parent.Head
    end
end)

I edited it to match your question

0
dont do local Parent... Imperialy 149 — 6y

Answer this question