OK, I am making a free-build game that has upgrades added to it.
I could use some help!
I am working on the first base right now, I have it in a Model called (BaseOne), and in that folder I have an (ObjectValue) named (Owner). I have 2 scripts first named (PurchaseHandler), second named (CoreScript).
I have 3 models, Buttons, PurchasedObjects, and Purchases, there are models in each one.
Ok, back to the top, In the WorkSpace I have a script that RestrictBuild, and ControlSpawning.
I need to get the ObjectValue in the BaseOne Model to Recognize what player has what base.
RestrictBuildScript:
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)
and, purchaseHandler script:
objects ={} wait(1) script.parent:WaitForChild("Buttons") for i,v in pairs(script.Parent.Buttons:GetChildren())do if v:FindFirstChild("Head") then local object = script.Parent.Purchaces:FindFirstChild(v.Object.Value) if object ~= nil then objects{object.name} = object:Clone() object:Destroy() else print("Button: "..V.Name.." is missing its object and has been removed.") v.Head.CanCollide = false v.Head.Transparency = 1 end v. Head.Touched:connect (function(hit) local player = game.players:GetPlayerFromCharacter(hit.Parent) if player ~= nil then if script.parent.owner.value== player then --- this is a problem i need to change if hit.parent:FindFirsChild("Humanoid") then --- it to the building plates i think if hit.Parent.Humanoid.Health > 0 then local cashmoney = game.ServerStorage.MoneyStorage:FindFirstChild((player.Name) if cashmoney ~= nil then if cashmoney.Value >= v.Price.Value then cashmoney.Value = cashmoney.Value - v.Price.Value objects{v.Objects.Value}.parent = script.Parent.PurchasedObjects v.Head.CanCollide = false v.Head.Transparency = 1 end end end end end end end end) end end
and finally, CoreScript:
Game.Players.PlayerAdded:connect (function (player) local cashmoney = Instance.new ("NumberValue",game.ServerStorage.MoneyStorage) cashmoney.Name = player.Name local isowner = Instance.new("BoolValue",cashmoney) isowner.Name = "OwnsTycoon" end) game.Players.PlayerRemoving:connect (function(player) local cashmoney = game.ServerStorage.MoneyStorage:FindFirstChild(player.Name) if cashmoney ~= nil then cashmoney:Save() end end
I need them all to work together to make one base.