Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I make a script that spawns a humanoid when you step on a block?

Sorry im a real noob at scripting, only started learning a few days ago, and I have been using the LTS Guide to scripting by sdfgw to learn so far. I was wondering if there was a list of functions somewhere, because in one of the guides it said that the function remove () obviously removes a block. The reason im asking this is because I want to make a script where if a block is touched, it spawns a humanoid.

Edit:

This is what I've got so far. I know it probably looks horrible to most people, but I basically just threw a bunch of things together and hoped it would work.

Soldier = workspace.Soldier1 if script.parent.part1.touched then Instance.new(Soldier, workspace.part1) end

I also tried this, but it is probably also completely wrong:

function newhuman () script.Parent: Instance.new(Soldier, workspace.part1) end

script.Parent.Touched:connect(newhuman)

6 comments

0

First of all, ROBLOX wiki has all the events, second of all use :Destroy() instead of remove. Remove does remove the object but it doesn't fully delete the object. Meaning that all your objects that you remove actually still exist in the game.

0

Could I use instance.new to spawn another humanoid if the brick is touched?

0

@LordDragonZord Destroy() will not fully delete an object either. It simply sets the Parent property to nil and locks it, whereas Remove() will only set it to nil; meaning a Remove()ed object could be "brought back to life" by reassigning its Parent property. You can still access a Destroy()ed object's properties, proving that it indeed still exists.

0

@yemumoncrack Yes, that is how you would proceed.

0

@Link150 Thank you, and this is why i still use :Remove()

2 answers

Ok, first I will tell you straight up it will error .touched and Instance.new(Solider). The more proper way would be .Touched event and Instance.new("") , you need apostrophes in the parenthesis when adding what child you want into workspace. You cannot add "Solider" into the workspace with Instance.new , the reason for it is because on Lua it does not exist. I will give an example code to demonstrate how you could do this. I will do this two ways: Creating a Humanoid into workspace, and making a replication of a model in ReplicatedStorage.

script.Parent.Touched:connect(function() --- Put this script in the brick if you wanted to use this
local hum =  Instance.new("Humanoid") --- To make it easier I am not putting the parent in by doing a comma then the parent.
hum.Parent = game.Workspace --- I didn't know how you wanted it in, so I just put it in workspace.
end)

Lets say you wanted to make a Solider appear in front of the player.

script.Parent.Touched:connect(function(hit) --- Same rule applies in putting this script in the part
local hum = hit.Parent:FindFirstChild("Humanoid") if hum ~= nil then ---Find if the humanoid and then checks to see if it is there
local rep = game:GetService("ReplicatedStorage")
local sold  = rep:WaitForChild("Solider") --- Waits for it to load so it does not error
if game.Workspace:FindFirstChild("Solider") == nil then
local clone = sold:Clone()
clone.Parent = game.Workspace
clone.CFrame = hit.Parent.Torso.CFrame + Vector3.new(0,0,8) --- It just makes sure that it doesn't spawn in the player who touched the part.
else
print("Already here")
end
end
end)

If one of these helped please be sure to accept the question as an answer! If you have any problems comment on the answer and I will be glad to help!

Wikipedia and 2010 free models are your best friend. Google everything.

2 comments

2

Roblox Wiki, Wikipedia only knows that Roblox is a MMO which started in 2006.

0

Basically what I'm trying to do in my script is "if the brick is touched then a humanoid will spawn", but I'm struggling to find info on how to spawn one. I know how to use the event .touched, I just don't know how to use it to spawn a humanoid

This discussion is preserved as it was. New answers, comments, and votes are closed.