This is the script where my Units are Summoned at Random. then it sets them as a datastore.
local Button = script.Parent.Parent
local Detector = script.Parent
local tower = nil
local towerRecieved = nil
local Summoned = game.ServerStorage.Summoned
local gui = nil
local summonPrice = 250
script.Parent.Triggered:Connect(function(player)
player.Gold.Value -= 250
local units = game.ReplicatedStorage.Units:GetChildren()
local unit = units[math.random(1, #units)]
local unitName = unit.Name
tower = player[unitName]
print(tower.Value)
while tower.Value == true do
unit = units[math.random(1, #units)]
unitName = unit.Name
wait(0.1)
end
player.PlayerGui.HUD.Summoning.Visible = true
player.PlayerGui.HUD.Summoning.Title.Text = "Summoning"
wait(1)
player.PlayerGui.HUD.Summoning.Title.Text = "Summoning."
wait(1)
player.PlayerGui.HUD.Summoning.Title.Text = "Summoning.."
wait(1)
player.PlayerGui.HUD.Summoning.Title.Text = "Summoning..."
wait(1)
player.PlayerGui.HUD.Summoning.Title.Text = "Summoning"
wait(1)
player.PlayerGui.HUD.Summoning.Title.Text = "Summoning."
wait(1)
player.PlayerGui.HUD.Summoning.Title.Text = "Summoning.."
wait(1)
player.PlayerGui.HUD.Summoning.Title.Text = "Summoning..."
wait(1)
player.PlayerGui.HUD.Summoning.Visible = false
tower.Value = true
print(tower.Value)
Summoned:Fire(towerRecieved, unit.Name)
player.PlayerGui.HUD.Summon.Visible = true
gui = player.PlayerGui.HUD.Summon
gui.Title.Text = unit.Title.Value
gui.Description.Text = unit.Description.Value
gui.Price.Text = unit.Price.Value
gui.UnitImage.Image = unit.Image.Image
wait(7)
player.PlayerGui.HUD.Summon.Visible = false
end)
local Datastore = game:GetService("DataStoreService")
local GoldStorage = Datastore:GetDataStore("GoldData")
local LevelStorage = Datastore:GetDataStore("LevelData")
local Summoned = game.ServerStorage.Summoned
-- Units
local TowerStorage = Datastore:GetDataStore("UnitTower")
local EnhancedTowerStorage = Datastore:GetDataStore("UnitEnhancedTower")
local HoracioStorage = Datastore:GetDataStore("UnitHoracio")
game.Players.PlayerAdded:Connect(function(Player)
local Gold = Instance.new("IntValue", Player)
Gold.Name = "Gold"
local Level = Instance.new("IntValue", Player)
Level.Name = "Level"
local placedTowers = Instance.new("IntValue", Player)
placedTowers.Name = "placedTowers"
local CurrentGold = GoldStorage:GetAsync(Player.UserId)
print(CurrentGold)
local CurrentLevel = LevelStorage:GetAsync(Player.UserId)
print(CurrentLevel)
if CurrentGold == nil then
CurrentGold = 0
end
if CurrentLevel == nil then
CurrentLevel = 0
end
Gold.Value = CurrentGold
Level.Value = CurrentLevel
placedTowers.Value = 0
Gold.Changed:Connect(function(NewValue)
GoldStorage:SetAsync(Player.UserId, NewValue)
end)
Level.Changed:Connect(function(NewValue)
LevelStorage:SetAsync(Player.UserId, NewValue)
end)
-- Units
-- Tower
local Tower = Instance.new("BoolValue", Player)
Tower.Name = "Tower"
local CTower = TowerStorage:GetAsync(Player.UserId)
print(CTower)
if CTower == nil then
CTower = true
end
Tower.Value = CTower
Summoned.Event:Connect(function(NewValue, tower)
if tower == Tower.Name then
TowerStorage:SetAsync(Player.UserId, NewValue)
end
end)
-- EnhancedTower
local EnhancedTower = Instance.new("BoolValue", Player)
EnhancedTower.Name = "EnhancedTower"
local CEnhancedTower = EnhancedTowerStorage:GetAsync(Player.UserId)
print(CEnhancedTower)
if CEnhancedTower == nil then
CEnhancedTower = false
end
EnhancedTower.Value = CEnhancedTower
Summoned.Event:Connect(function(NewValue, tower)
if tower == Tower.Name then
EnhancedTowerStorage:SetAsync(Player.UserId, NewValue)
end
end)
-- Horacio
local Horacio = Instance.new("BoolValue", Player)
Horacio.Name = "Horacio"
local CHoracio = HoracioStorage:GetAsync(Player.UserId)
print(CHoracio)
if CHoracio == nil then
CHoracio = false
end
Horacio.Value = CHoracio
Summoned.Event:Connect(function(NewValue, tower)
if tower == Tower.Name then
HoracioStorage:SetAsync(Player.UserId, NewValue)
end
end)
end)
game.ServerStorage.Bindables.MobKilled.Event:Connect(function(player)
local random = math.random(80,150)
player.Gold.Value += random
end)
This is my datastore scripts, all the other datastores save apart from the towers, they always default to false. What is wrong?