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

Why does this create game button not work?

Asked by
Asirix 15
10 years ago

I have tried this as a server script, and a local script.

game:GetService('TeleportService').CustomizedTeleportUI = true

ds = game:GetService("DataStoreService"):GetGlobalDataStore()

local Button = script.Parent

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

function _sendPlayerToBuildZone(player)
    local playerIdentity = player.Name .. '(' .. player.userId .. ')'

    local playerKey = 'player_' .. player.userId
    local playerData = ds:GetAsync(playerKey)

    if playerData then
        if playerData.personalPlaceId <= 0 then
            playerData = nil
        end 
    end

    if not playerData then              
        newPlaceId = game:GetService(AssetService):CreatePlaceAsync(script.Parent.Parent.GameName.Text .. ' by ' .. playerIdentity, 92697995)

        playerData = {
            personalPlaceId = newPlaceId                    
        }

        ds:SetAsync(playerKey, playerData)  
    end         

    if playerData and playerData.personalPlaceId then   
        game:GetService('TeleportService'):Teleport(playerData.personalPlaceId, player)         
    end 
end

function Create()
    local player = getPlayer(Source)    
    if player then
        if player.userId > 0 then       
            sendPlayerToBuildZone(player)
        end     
    end 
end

script.Parent.MouseButton1Click:connect(Create)

Answer this question