Please check the two following scripts
1
local player = game.Players.LocalPlayer local userInputService = game:GetService("UserInputService") local remote = game:GetService("ReplicatedStorage"):WaitForChild("Tower")
for i, v in pairs(script.Parent:GetChildren())do if v:IsA("Frame") and v:FindFirstChild("Place") then v:FindFirstChild("Place").MouseButton1Down:Connect(function() if player[v.Name].Value ~= "Empty" then if script.Placing.Value == nil then local mouse = player:GetMouse() script.Placing.Value = v
spawn(function() local t = false local clicked = false while script.Placing.Value ~= nil do wait() if t == false then local tower = game:GetService("ReplicatedStorage").Towers:FindFirstChild(player[v.Name].Value):Clone() if tower then tower.Name = player.Name..player[v.Name].Value tower:Clone().Parent = workspace end t = true end if workspace:FindFirstChild(player.Name..player[v.Name].Value) then local part = mouse.Target mouse.TargetFilter = workspace:FindFirstChild(player.Name..player[v.Name].Value) if part ~= nil and part.Parent.Name == "Placeable" then workspace:FindFirstChild(player.Name..player[v.Name].Value).Indicator.BrickColor = BrickColor.new("Lime green") workspace:FindFirstChild(player.Name..player[v.Name].Value).HumanoidRootPart.BodyPosition.Position = Vector3.new(mouse.Hit.p.X, part.Position.Y, mouse.Hit.p.Z) userInputService.InputBegan:Connect(function(Input, GPE) if Input.UserInputType == Enum.UserInputType.MouseButton1 and part ~= nil and part.Parent.Name == "Placeable"and clicked == false then clicked = true THIS IS WHERE VALUE VALUE2 AND VALUE 3 in [ ] remote:FireServer. [. ("Place", v.Name, workspace:FindFirstChild(player.Name..player[v.Name].Value).HumanoidRootPart.BodyPosition.Position). ] script.Placing.Value = nil wait(0.5) if workspace:FindFirstChild(player.Name..player[v.Name].Value) then workspace:FindFirstChild(player.Name..player[v.Name].Value):Destroy() end end end) elseif part == nil or part.Parent.Name ~= "Placeable" then workspace:FindFirstChild(player.Name..player[v.Name].Value).Indicator.BrickColor = BrickColor.new("Really red") workspace:FindFirstChild(player.Name..player[v.Name].Value).HumanoidRootPart.BodyPosition.Position = mouse.Hit.p end end end end) elseif script.Placing.Value ~= nil and script.Placing.Value == v then script.Placing.Value = nil if workspace:FindFirstChild(player.Name..player[v.Name].Value) then workspace:FindFirstChild(player.Name..player[v.Name].Value):Destroy() end end end end) v.TowerName.Text = player[v.Name].Value player[v.Name].Changed:Connect(function() v.TowerName.Text = player[v.Name].Value end) end
end
2 Saving and tower placement script
local data = game:GetService("DataStoreService"):GetDataStore("TowerDataStore") local remote = game:GetService("ReplicatedStorage"):WaitForChild("Tower")
remote.OnServerEvent:Connect(function(Player, value, value2, value3) if value == "Place" then local tower = game:GetService("ReplicatedStorage").Tower[Player[value2].Value]:Clone() tower.Indicator:Destroy() tower.HumanoidRootPart.BodyPosition:Destroy() tower.Parent = workspace tower.HumanoidRootPart.BodyPosition.Position = value3 end end)
function save(plr) local saveData = {} for i, v in pairs(plr:GetChildren())do if v:IsA("StringValue") then saveData[v.Name] = v.Value end end data:SetAsync(plr.UserId, saveData) end
game.Players.PlayerAdded:Connect(function(plr) for i = 1, 4 do local x = Instance.new("StringValue", plr) x.Name = "Tower"..tostring(i) x.Value = "Empty" end local getData local success, errorm = pcall(function() getData = data:GetAsync(plr.UserId) end) if success then if getData then for i, v in pairs(getData) do plr:FindFirstChild(i).Value = v end end end end)
game:BindToClose(function() for _, v in pairs(game.Players:GetChildren())do save(v) end end) game.Players.PlayerRemoving:Connect(function(plr) save(plr) end)