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)
print('I was stepped on by ' .. PartThatTouched.Name .. '! Ack!')
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
if v:IsA('BasePart') then
print('I\'m a part! :D')
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
Now we should all be done. Are we?
Yay!
Ok. :p
Stuff touched on, but never really explained
Touched - Fires when an object touches another, and returns the part that touched.
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.
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."
GetChildren - Returns a table with the children that were within the parent.
IsA - Returns whether an object was a specific class, such as if it was a Part or Fire.
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. ;)
1 comment
Second answer after a month! Highfive! ...No? Aw. :c