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

Why my teleport script is not working when I touched the Model?

Asked by 5 years ago
Edited 5 years ago

I made the script that when it touches the Model, it teleports back to the parts named "Spawn1","Spawn2" until "Spawn16" so there are 16 parts that is parented by "Spawn".The "Spawn" is parented by "Mega Challenge". But the script says this "Spawn1 is not a valid member of Model" "Spawn8 is not a valid member of Model" "Spawn5 is not a valid member of Model" It shows when I touched the Model named "Hammer" parented by "TrapPlatformHammer".The "TrapPlatformHammer" is parented by "Mega Challenge" too. Can you help me? I'm confused This is the script.

script.Parent.Touched:connect(function(hit)

if hit.Parent:FindFirstChild('Humanoid') then

local num = math.random(1,16)

hit.Parent.Head.CFrame = CFrame.new(game.Workspace.MegaChallenge.Spawns("Spawn"..num).Position)

end

end)
0
Would changing Spawns() to Spawns[] do anything? Using brackets treats it like a table. DeceptiveCaster 3761 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
  1. you should use :MoveTo, that always works for me.
  2. It's not game.Workspace.MegaChallenge.Spawns("Spawn"..num).Position, but ["Spawn"..num].Position.
  3. I just made the script for you, fixed, because I was bored. (Not tested)
  4. script.Parent.Touched:connect(function(hit)

    if hit.Parent ~= nil then local player = game.Players:WaitForChild(hit.Parent.Name)

    local num = math.random(1,16)

    player.Character:MoveTo(game.Workspace.MegaChallenge.Spawns["Spawn"..num].Position)

    end

    end)

0
why is connect not capitalized? Staven2u 2 — 5y
0
As I said, not tested, and I'm sometimes dumb. Capitalize it RazerGamingKeyboard 17 — 5y
Ad

Answer this question