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

Why does this script not work?

Asked by 8 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.
function touched(par)
if game.Name == "Basic Obby 1" then
    wait(1)
print(game.Name)
print("Teleporting")
id = game:GetService("AssetService"):CreatePlaceAsync("Obby", "Place For Player!") 
local tele = game:GetService("TeleportService")
tele:Teleport(id, getPlayer(par))

end
end


function getPlayer(Part)
    local Humanoid = Part.Parent:FindFirstChild('Humanoid')
    if (Humanoid ~= nil) then
        local Character = Humanoid.Parent
        if (Character ~= nil) then
            return game:GetService('Players'):GetPlayerFromCharacter(Character)     
        end
    end
end

script.Parent.Touched:connect(touched)

1 answer

Log in to vote
1
Answered by
funyun 958 Moderation Voter
8 years ago

Why make a getPlayer function when you already have a GetPlayerFromCharacter function?

function touched(par)
    local player = game.Players:GetPlayerFromCharacter(par.Parent)

    if game.Name == "Basic Obby 1" and player then
            wait(1)
        print(game.Name)
        print("Teleporting")
        local id = game:GetService("AssetService"):CreatePlaceAsync("Obby: " .. player.Name, game.PlaceId, " Place For Player!") 
        local tele = game:GetService("TeleportService")
        tele:Teleport(id, player)
    end
end

script.Parent.Touched:connect(touched)
Ad

Answer this question