Regenerating Part (2)

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to make a part (a boulder, in this case) that rolls down a tunnel, killing players it runs into (I got that part down, except I am having a bit of trouble with the boulder as it gets stuck) but then when it flies into a hole at spawn into the void and “dies” I want it to respawn at set coordinates
  2. What is the issue? Include screenshots / videos if possible!
    The issue is that I do not know how to script myself (I’m more of a builder, though even my buildings aren’t exactly like 5-star amazing) and I would be very confused if someone merely said “try adding a blah blah blah to a blah blah blah blah” (also note that if I’m gonna be honest, I do understand a little bit of scripting… but its such a small amount that it would be no help with what I’m trying to do. Also, if possible I will try to get back to this with a video or screenshot, though I’m not sure when or how or even if that will happen
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have tried multiple things;
  • Googling it, but since in some cases google is utterly useless and came up with irrelevant things, that was no help

  • I tried looking around on here but found nothing related to what I was looking for

  • I tried posting about it on here but it got taken down (to the admin who took it down, I say this with all due respect, and I’m not angry about it, as I was a brand-new member and still am, and also I was not trying to do anything bad, I’m just a 14 year old looking for answers)

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

-- This is an example Lua code block

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

1 Like

Scripting can be a difficult concept to understand, but once you get to know it well it shouldn’t be too much of an issue! Usually you have to understand it from a different point of view to make it easier :upside_down_face:

So for your instance, you’re wanting to create a Boulder that Kills players whenever they touch it correct? And when it falls down at the end, it’ll Regen at a specific position

Well, the first thing we can do is go ahead & create a Script inside our said “Boulder” and reference our variable and kill function:

local Boulder = script.Parent --The script's Parent would be referring to the Boulder

local function KillPlayer(Hit)
    local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)

    if Player then
        local Character = Hit.Parent

        Character.Humanoid:TakeDamage(100)
    end
end)

Boulder.Touched:Connect(KillPlayer)

Now let’s stop here, cause we’re starting to get a bit ahead of ourselves here :thinking: Now what is a function? It’s basically lines of code that can initiate a specific task depending on what you’re going for here (Whether it be grabbing a Carton of Milk from the Grocery Store and never coming back, or grabbing something from a table)

We can also use functions to connect to Events, so that they’ll only fire whenever a specific event occurs (Such as a number changing, or a part moving) so we can use the Touched Event to connect our KillPlayer function

In our function KillPlayer, we’re creating a separate local variable which would detect for the Player’s Character Model (Both the Player and the Character are different from each other), so we call a function that’s called GetPlayerFromCharacter(), and that would check if the Hit’s Parent would be equal to a Character Model, and if it is then it would kill the Player whenever they touch it!

Now, we’ve created our Kill function & our variable, but how would we reset its coordinates after it reaches the end? Well, one thing we could potentially do is create another script inside ServerScriptService, and add a ChildRemoved Event which would fire when a Child gets removed from a specific area

The next thing we can do is actually clone our Boulder, and reference it inside ServerStorage so that we can clone it again whenever it reaches the V O I D

local Boulder = game.ServerStorage:WaitForChild("Boulder")

local function RespawnBoulder(Child)
    if Child.Name == "Boulder" then
        local BoulderClone = Boulder:Clone()
        BoulderClone.Parent = workspace
    end
end

workspace.ChildRemoved:Connect(RespawnBoulder)

Again, with our function we’re connecting this to a ChildRemoved Event which would only fire whenever a Child gets removed inside the workspace, and we’re checking if the Child’s Name is equal to Boulder since it would get destroyed inside the void

And hopefully, our full code should look like this in 2 pieces!

--Script inside the Boulder
local Boulder = script.Parent --The script's Parent would be referring to the Boulder

local function KillPlayer(Hit)
    local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)

    if Player then
        local Character = Hit.Parent

        Character.Humanoid:TakeDamage(100)
    end
end)

Boulder.Touched:Connect(KillPlayer)
--Script that will regen the Boulder (In ServerScriptService)
local Boulder = game.ServerStorage:WaitForChild("Boulder")

local function RespawnBoulder(Child)
    if Child.Name == "Boulder" then
        local BoulderClone = Boulder:Clone()
        BoulderClone.Parent = workspace
    end
end

workspace.ChildRemoved:Connect(RespawnBoulder)

Of course do feel free to ask anymore questions if you are confused :sweat_smile: Thank you for listening to my ted talk

2 Likes

Ok I finally got around to testing it and the one in SeverScriptService didn’t work. I’m not angry or anything, just confused. I’ll try to get a video of it. :slight_smile: :sweat_smile: :sweat_smile:

Really now? If you can, try to add some print statements in both of the scripts

You can just do something like this:

print("Lalalalalala this is a test")

And check your Output if it does print or not


This is the output… not sure what’s happening here