How to Make Weapon Giving Teleporters
Introduction
This tutorial will explain how to make a weapon giving teleporter. These teleporters can be used to give weapons to players when going into a certain area. A good example of this is to have a safe place where the player can respawn and have no weapons, but, when the player teleports to a different area outside of this "safehouse", the player will bring with themselves weapons for protection. It is recommended that you have an understanding of GoodBlox Studio before you begin.
Getting the Teleporters
The first step is to open GoodBlox Studio in "Edit" mode with whatever place you want to have these Teleporters. Next, open the "Insert" tab on the top-left of the screen. Go to "All Models" and search for "Teleporters". Find two working teleporters and Add them to the place that you are working on. (Note: The teleporters will look like two bricks)
Adding and Placing the Script
Go to Insert> Object and click on "Script". That will add a script to the game. Open the "Teleporter" Model and place the new script into one of the Teleporters of your choice.
Editing the Script
Open the script that you placed into the Teleporter, remove any text that is in the script, and copy then paste the following code into the script:
------------------------------------
modelname = "teleporter1b" --Rename this to whatever you want the name of your teleporter to be.
------------------------------------
function onTouched(part)
if part.Parent ~= nil then
local h = part.Parent:findFirstChild("Humanoid")
if h~=nil then
local teleportfrom=script.Parent.Enabled.Value
if teleportfrom~=0 then
if h==humanoid then
return
end
local teleportto=script.Parent.Parent:findFirstChild(modelname)
if teleportto~=nil then
local torso = h.Parent.Torso
local location = {teleportto.Position}
local i = 1
local x = location[i].x
local y = location[i].y
local z = location[i].z
x = x + math.random(-1, 1)
z = z + math.random(-1, 1)
y = y + math.random(2, 3)
local cf = torso.CFrame
local lx = 0
local ly = y
local lz = 0
script.Parent.Enabled.Value=0
teleportto.Enabled.Value=0
torso.CFrame = CFrame.new(Vector3.new(x,y,z), Vector3.new(lx,ly,lz))
script.Parent.Enabled.Value=1
teleportto.Enabled.Value=1
else
print("Could not find teleporter!")
end
end
end
end
end
script.Parent.Touched:connect(onTouched)
function getPlayer(humanoid)
local players = game.Players:children()
for i = 1, #players do
if players[i].Character.Humanoid == humanoid then return players[i] end
end
return nil
end
function onTouch(part)
local human = part.Parent:findFirstChild("Humanoid")
if (human == nil) then return end
local player = getPlayer(human)
if (player == nil) then return end
--Put the weapon you want that the Teleporter will give in the Lighting folder.
game.Lighting:findFirstChild("WeaponName"):clone().Parent = player.Backpack
--Copy the above line for the Teleport to give multiple weapons.
--Remember to replace "WeaponName" with the name of the weapons in the Lighting.
--The name MUST match what is in the Lighting.
--For more help see: http://wiki.goodblox.xyz/index.php?title=How_to_Make_Weapon_Giving_Teleporters
wait(0.5)
end
script.Parent.Touched:connect(onTouch)
Choosing and Placing Weapons
(Most of these notes are in the Script, however, they will be listed here in case you missed them.) Put the weapons that the Teleporter will give into the "Lighting" section. Replace "WeaponName" with the name of the weapons in the Lighting. The name must exactly match whatever the name of the Weapon in the Lighting is, otherwise it will not work.