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

Can somoen help me with adding Models to my script?

Asked by 9 years ago

OK, im new to this ( I think that is why people are always giving me - score LoL)

I am making a Free-Build map.

I have all the script for it and the map built.

I am adding some twist, I added turrets, towers, and upgrades.( all that can be bought with cash from kills)

I have the script that gives all 9 players their area to work in to free build.

I can not figure out how to add all of my upgrade so that they ( and only them) can buy them and use them.

here is the script that gives the players their ownership.

function waitForChild(instance, name)
    while not instance:FindFirstChild(name) do
        instance.ChildAdded:wait()
    end
end

waitForChild(game, "Workspace")
waitForChild(game.Workspace, "BuildingPlates")
waitForChild(game, "Players")

local activeParts
if(game.Workspace:FindFirstChild("ActiveParts")==nil) then
    activeParts = Instance.new("Model")
    activeParts.Name = "ActiveParts"
    activeParts.Parent = game.Workspace
else
    activeParts = game.Workspace.ActiveParts
end

local buildingPlates = game.Workspace.BuildingPlates

local assigning = false

function addPlayer(player)

    print("addPlayer()", "waiting for previous addPlayer...")

    while(assigning) do 
        assigning.Changed:wait()
    end

    assigning = true

    print("addPlayer()", "waiting for playerNumber...")
    waitForChild(player, "playerNumber")
    print("addPlayer()", "assigning...")

    if(player.playerNumber.Value == 0) then
        -- This is an extra player.  He has playerNumber 0, and spawns in a different spawn point on the side.
        -- He doesn't get a stamper tool.
        print("addPlayer() playerNumber:", player.playerNumber, "stamperTool name:", player.Backpack.StamperTool.Name, "Removing stamperTool.")
        -- hint("All building areas are taken. If you want to build, leave and join again.")
        --waitForChild(player.Backpack, "StamperTool")
        --player.Backpack.StamperTool:Remove()
        --[[
        game.Workspace.Message.Text = player.Name .. " joined, and has playerNumber " .. player.playerNumber.Value .. " and doesn't own a baseplate."
        wait(3)
        game.Workspace.Message.Text = ""
        --]]
    else
        -- He has his own plate.  Get him set up.

        -- Give him a model for all his parts
        if(activeParts:FindFirstChild(player.Name .. "'s parts")==nil) then
            local model = Instance.new("Model")
            model.Name = player.Name .. "'s parts"
            model.Parent = activeParts
        end

        -- Assign plate
        print("assignPlate() playerNumber not zero:", player.playerNumber.Value)
        waitForChild(buildingPlates, "Plate"..tostring(player.playerNumber.Value))

        targetPlate = buildingPlates:FindFirstChild("Plate"..tostring(player.playerNumber.Value))

        -- Create "Player" StringValue inside targetPlate if none exists (for some reason, it gets deleted sometimes when playing online.)
        if(targetPlate:FindFirstChild("Player") == nil) then
            local _player = Instance.new("StringValue")
            _player.Name = "Player"
            _player.Parent = targetPlate
        end
        targetPlate.Player.Value = player.Name

        print("assignPlate()", "complete.", targetPlate.Name, "belongs to", player.Name)
        --[[
        game.Workspace.Message.Text = player.Name .. " joined, and has playerNumber " .. player.playerNumber.Value .. " and owns baseplate " .. targetPlate.Name .. "."
        wait(3)
        game.Workspace.Message.Text = ""
        --]]
    end
    assigning = false
end

function removePlayer(player)
    -- Delete his model
    waitForChild(game.Workspace, "ActiveParts")
    waitForChild(game.Workspace.ActiveParts, player.Name .. "'s parts")
    local model = game.Workspace.ActiveParts:FindFirstChild(player.Name .. "'s parts")
    model:remove()

    -- Free his plate
    local takenPlates = buildingPlates:GetChildren()
    for i = 1, #takenPlates do
        if takenPlates[i].Player.Value == player.Name then
            takenPlates[i].Player.Value = ""
        end
    end

end

-- In case we already have players by the time this script initializes
local players = game.Players:GetChildren()
for i = 1, #players do
    addPlayer(players[i])
end

game.Players.PlayerAdded:connect(function(player)
    addPlayer(player)
end)

game.Players.PlayerRemoving:connect(function(player)
    removePlayer(player)
end)

can someone help me please?

0
To make only the own use it, make a check for the player. Possible make a StringValue when someone gains ownership, then have the script check that variable's value and players name, if it matches, continue with code, if not, don't. alphawolvess 1784 — 9y
0
Can you explain what you mean by: "I can not figure out how to add all of my upgrade so that they ( and only them) can buy them and use them." Merely 2122 — 9y
0
Well, i have 9 pads , one for each player were they can build anything. but on the outside i made some stuff, like walls, turrets towers, and upgrades. i want them to be able to buy them with cash. but i dont want other players able to buy them, or use them.. so its kind of a freebuild/military/tycoon snipers007 0 — 9y
0
The cash is made from killing other players. snipers007 0 — 9y

Answer this question