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

How to spawn a OnTouch brick with a scriptbuilder?

Asked by 9 years ago

Here's a script that deals with Touch, so I know it can be done in script builder.

local p = Workspace.jaytheidiot
local tableOfChildren = p:GetChildren()
function Touch(part)
local human = part.Parent:FindFirstChild("Humanoid")
if human then
human:TakeDamage(human.MaxHealth)
end
end
for i,v in pairs(tableOfChildren) do
if v:IsA("BasePart") then
v.Touched:connect(Touch)
end
end

Now what I need to do is spawn a brick and make it have an Touch event. Here's a brick spawning script.

Dan = Workspace.jaytheidiot.Torso
p = Instance.new("Part")
p.Parent = Workspace.Bucket
p.Size = Vector3.new(100,10,100)
p.Anchored = true
p.BrickColor = BrickColor.new(1032)
p.Material = "SmoothPlastic"
p.CFrame = CFrame.new(Dan.CFrame.X,Dan.CFrame.Y-7,Dan.CFrame.Z)

What I want to happen when that block is touched is change the Touched player's torso CFrame to something so I can move them. Any ideas how to make this work? We can use CFrame.new(1,1,1) as an example CFrame. I'll change that to what I need later.

1 answer

Log in to vote
1
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago

So if i'm not mistaken then you want to create a sort of teleporter..

Just add a touched event to your 'p' variable, which is the part..

EX;

p.Touched:connect(function(hit) --The parameter 'hit' can be used for the part that touched.
    if hit.Parent:FindFirstChild("Humanoid") ~= nil then --Check if they have a humanoid
        hit.Parent.Torso.CFrame = CFrame.new(1,1+5,) --Move them, add 5 to the y scale so they're not stuck in the base.
    end
end)

This is the basics of touched events. If you want to look over more if how this would work then read up on this: Teleportation Guide

Hope I Helped

Ad

Answer this question